Android SingleTask, SingleTop and Home Button

My application has behavior that I do not understand. I have MainActivity A as a SingleTask . It calls Activity B, which is also SingleTask . When I click the Home button in the second step to open another application, and after that I try to switch to my mantaining Home application is pressed, I always go to Main Activity , and I need to open the second activity maintaining the state that was when the Home button was pressed.

I tried installing the second asset on singleTop and it does not work.

Any help?

+4
source share
1 answer

The behavior of the activity stack back is no longer strange when defining the main activity using singleTask at the same time:

 <activity android:name=".MainActivity" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

To make matters worse, there is no clear explanation in the official developer guide regarding this particular use case. Some sections related to this topic even contradict each other.

Try using launchMode = "standard" on MainActivity A and launchMode="singleTask" on Activity B to give a description of the expected behavior.

+4
source

Source: https://habr.com/ru/post/1397445/


All Articles