Sino Raj Sino Raj - 13 days ago 4
Android Question

'FLAG_ACTIVITY_REORDER_TO_FRONT' in new flavors of Android OS(4.4 & later)

Recently, I faced a problem to re-initiate Activity that's already in back-stack. The flag FLAG_ACTIVITY_REORDER_TO_FRONT is the best solution for manage this problem. But in Android 4.4 & later it isn't work well(some times Activity view is going to freezing state or Application minimizes itself, menu isn't inflated to re-initiated Activity or Keyboard isn't allow to enter something to text area) but in previous versions this flag re-initiate's the Activity, and removed from back stack. Please review this link for more details.


In Android 4.4 & later, the application misbehaves when FLAG_ACTIVITY_REORDER_TO_FRONT flag is used in Activity creation. The major issues are, some times Activity is going to freeze state, when navigate to another activity key board isn't working well(key board is shown but user can't enter anything to text area), didn't inflate menu, or Application navigates to minimize state.

I think this issue is related to back-stack and flow of activity, when launcher activity(in my application, SplashScreenActivity is a launcher) finishes, then sub-activity causes some problem when using FLAG_ACTIVITY_REORDER_TO_FRONT to re-initiate previous Activity. So in this scenario, don't kill launcher or parent activity & start next activity using startActivityForResult(childAcivityIntent, requestcode), & kill parent activity at the time of onActivityResult call. And also remember don't use singleInstance or singleTop flags in child & parent activities.

private void onStartNextActivity() {
        Intent mIntent= new Intent(SplashscreenActivity.this, ChildActivity.class);
       startActivityForResult(mIntent, 1111);

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);