情景:
在A界面onResume中跳转到B界面,B界面中启动截图服务,之后导致截图服务出现奔溃,提示截图必须在前台服务中进行
解决办法:
延迟启动界面跳转
代码:
new Handler().postDelayed(() -> {
Intent intent2 = new Intent(ShowResultActivity.this, ScreenCaptureActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent2);
finish();
}, 300);
注:最好是在Activity的生命周期走完之后再进行界面的跳转