FLAG_ACTIVITY_REORDER_TO_FRONT之ANR问题(Android L)
2016-07-07 15:21
736 查看
Issue: https://code.google.com/p/android/issues/detail?id=169768
问题摘要:
===============================================================
1)The app starts with Activity A, which simply shows a button called "Launch B". 2)Press this button -- this executes startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityB.class). 3)Activity B becomes active, which do some UI and backhand loading operation on UI thread. 4)After pressing back from Activity B, OnBackPressed Of Activity B, this executes startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityA.class). 5)Activity A's onResume() is called as expected and everything looks fine (I can see Activity A content again). 6)Press the device's Back key and App freezes for around 10 seconds or more and comes out of application. Without calling onPause(), onDestroy(). (So it may be anr with certain logs) 7)Sometime or may be repeating same above step for 4-5 times it also unfortunately force close googlequicksearchbox
After looking at system logs: found some important logs:
E/ActivityManager( 958): Reason: Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)
===============================================================
解决方式(workaround):
在FLAG_ACTIVITY_REORDER_TO_FRONT的目标Activity的onNewIntent中用FLAG_ACTIVITY_NEW_TASK start一个创建即消失的activity
示例:
其中
问题摘要:
===============================================================
1)The app starts with Activity A, which simply shows a button called "Launch B". 2)Press this button -- this executes startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityB.class). 3)Activity B becomes active, which do some UI and backhand loading operation on UI thread. 4)After pressing back from Activity B, OnBackPressed Of Activity B, this executes startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityA.class). 5)Activity A's onResume() is called as expected and everything looks fine (I can see Activity A content again). 6)Press the device's Back key and App freezes for around 10 seconds or more and comes out of application. Without calling onPause(), onDestroy(). (So it may be anr with certain logs) 7)Sometime or may be repeating same above step for 4-5 times it also unfortunately force close googlequicksearchbox
After looking at system logs: found some important logs:
E/ActivityManager( 958): Reason: Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)
===============================================================
解决方式(workaround):
在FLAG_ACTIVITY_REORDER_TO_FRONT的目标Activity的onNewIntent中用FLAG_ACTIVITY_NEW_TASK start一个创建即消失的activity
示例:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent trickIntent = new Intent(context, TrickActivity.class);
trickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(trickIntent);
}
}
其中
public class TrickActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
@Override
public void finish() {
super.finish();
// disable the animation
overridePendingTransition(0, 0);
}
}
相关文章推荐
- 解决FLAG_ACTIVITY_REORDER_TO_FRONT方式启动Activity,按返回键会出现卡死(ANR)的问题
- android Intent的FLAG_ACTIVITY_CLEAR_TOP跟FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent.FLAG_ACTIVITY_REORDER_TO_FRONT在华为C8817D上异常,使用Intent.FLAG_ACTIVITY_CLEAR_TOP直接回到桌面
- FLAG_ACTIVITY_CLEAR_TOP 和 FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- --------------------FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT用法
- FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT用法
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- ntent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT用法
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT小结
- FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT