Android: navigating up to the parent activity recreates the parent activity

前端 未结 2 1253
栀梦
栀梦 2021-01-06 01:44

I have a SearchAcvitity which has a child PersonActivity. Each are FragmentActivity\'s. Here\'s my manifest file:



        
相关标签:
2条回答
  • 2021-01-06 02:12

    I think someone may have asked the question before: onCreate being called on Activity A in up navigation

    Basically it is expected behavior. You need to save state into the bundle, which you can restore in onCreate.

    0 讨论(0)
  • 2021-01-06 02:18

    UP navigation launches the parent Activity with Intent.FLAG_ACTIVITY_CLEAR_TOP. The standard behaviour of this flag is to finish all Activities that are on top of the parent Activity in the task stack including the parent Activity itself and then launch a new instance of the parent Activity**. If you want to resume the existing instance of the parent Activity, then you can set the following in the manifest for the parent Activity:

    android:launchMode="singleTop"
    

    When CLEAR_TOP and SINGLE_TOP are used together, this will resume an existing instance of the parent Activity. In this case, onCreate() will not be called on the resumed parent Activity, but instead onNewIntent() will be called instead.

    0 讨论(0)
提交回复
热议问题