How to resume activity instead of restart when going “up” from action bar

前端 未结 2 1290
感动是毒
感动是毒 2021-01-31 15:15

I have two activities. Say Activity A and Activity B.
From Activity A I click a button to launch Activity B

相关标签:
2条回答
  • 2021-01-31 16:02

    Should've added as an answer instead of a comment.. but here you go so you can accept if you want so others can see if necessary.

    https://stackoverflow.com/a/16147110/3286163

    Basically, to summarize the android will always recreate the activity unless you specify it not to with

    android:launchMode="singleTop"
    

    Note: it will not work if the returning activity is not on the top of the back stack as mentioned in the reference.

    For anyone else, please upvote the answer in the url instead of mine if you find this useful.

    0 讨论(0)
  • 2021-01-31 16:10

    You can also achieve the same outcome programatically

    Intent upIntent = NavUtils.getParentActivityIntent(this);
    upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    NavUtils.navigateUpTo(this, upIntent);
    
    0 讨论(0)
提交回复
热议问题