I have 2 actions: Activity A and Activity B. Activity. The startup mode is standard, and the Activity B startup mode is singleTask.
<activity android:name=".AActivity" android:label="@string/app_name" android:launchMode="standard"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="dd"></data> <data android:host="a"></data> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> <activity android:name=".BActivity" android:label="@string/app_name" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="dd"></data> <data android:host="b"></data> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity>
I launched the application and the Activity Launcher starts. Then I press the Home button and return to the main screen of the phone. Then launch the browser application and enter the following:
dd:
to open Activity B. The system goes to my application and launches action B on top of activity A. At this point, if I press the back button, activity B will appear and I will see activity A.
This is not what I expected, because the Android documentation has:
For SingleTask actions, the system creates a new task and starts the action at the root of the new task. However, if an activity instance already exists in a separate task, the system redirects the intent to the existing instance by calling its onNewIntent () method instead of creating a new instance. Only one instance of activity can exist at a time.
What I understand from these sentences, in my case, since an instance of Activity B does not exist, a new task should have been started, and it should have only Activity B in its stack (another instance of my application should still exist in a separate task , and it must have Activity A in its stack). Then, if I click back when I was in Activity B, since this is the only action in the backstack, it pops up and the system returns to the browser.
Why is this not so? How does the Android system know that my application is open and moving to it, and launches activity B on top of the existing application stack instead of starting another instance of my application and allowing two instances of my application to have their own stacks? What does creating an instance of activity in a new task mean? Can anyone explain?
Thanks.