ActionBar up navigation recreates parent activity instead of onResume

前端 未结 6 2033
天涯浪人
天涯浪人 2020-12-04 16:26

I\'m using the recommended approach for Up Navigation and my code looks like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switc         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 16:52

    This code worked for me:

    Intent upIntent = NavUtils.getParentActivityIntent(this);
    if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
        // This activity is NOT part of this app's task, so create a new task
        // when navigating up, with a synthesized back stack.
        TaskStackBuilder.create(this)
            // Add all of this activity's parents to the back stack
            .addNextIntentWithParentStack(upIntent)
            // Navigate up to the closest parent
            .startActivities();
    } else {
        // This activity is part of this app's task, so simply
        // navigate up to the logical parent activity.
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, upIntent);
    }
    
    return true;
    

    No finish() invocation required.

提交回复
热议问题