Learning Journey - Android's onNewIntent()

When onNewIntent will be executed: 

Premise: When the instance of the Activity already exists in the Task and Back stack (or in layman's terms, you can return to the Activity by pressing the return key), when using the intent to start the Activity again, if the startup does not create the Activity, the system will call the onNewIntent() method of the original instance to handle the intent.

  And the system will not create a new instance of the Activity in the following cases:

   1. If the android:launchMode of the Activity in the Manifest is defined as singleTask or singleInstance . (If ActivityA is already in the stack)

   2. If the android:launchMode of the Activity in the Manifest is defined as singleTop and the instance is located at the top of the activity stack of A , then A's onNewIntent will be called.

   3. If the android:launchMode of the Activity in the Manifest is defined as singleTop, and the above intent contains the Intent.FLAG_ACTIVITY_CLEAR_TOP flag.

   4. If the above intent contains the Intent.FLAG_ACTIVITY_ CLEAR _TOP flag and contains the Intent.FLAG_ACTIVITY_ SINGLE _TOP flag .

   5. If the above intent contains the Intent.FLAG_ACTIVITY_ SINGLE_TOP flag and the instance is located at the top of the Back stack.

onNewIntent is not called

      When the LaunchMode of ActivityA is Standard, a new instance is started every time ActivityA is started, which has nothing to do with the original one, so the onNewIntent method of the original ActivityA will not be called

Usage example

 The processing logic in a DActivity needs to jump to the third ThreeFragemnt in the four Fragments of MainActivity

As shown on the Internet A->B->C->A, where C jumps back to A with parameters, and A needs to output processing logic

 



 

Guess you like

Origin blog.csdn.net/qq_22576071/article/details/81213684