Android: unexpected behavior of recent applications

Our application has 2 actions - A MainActivity (associated with the Launcher icon) and AuxActivity for handling URI events.

I see a problem with this scenario when my application initially exited:

  • Open a browser, click the URI to launch AuxActivity .

  • AuxActivity exit (calls finish ()), the user returns to the browser.

  • The user opens the latest applications (long press on the house) and selects my application.

Instead of launching MainActivity , I see that AuxActivity launched with the same intention as the click URI ( android.intent.action.VIEW ) represents.

Now instead of step 3, if the user needs to open my application through the "Home screen" icon, I will return to MainActivity , as expected.

How can I get step 3 to run MainActivity instead?

+4
source share
3 answers

Based on Tim's suggestion, how about adding

 android:excludeFromRecents="true" 

To the auxActivity list in the manifest? Does it help?

+1
source

Put this in AuxActivity onCreate:

 if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) > 0) { // do something different eg launch MainActivity } 
+2
source

Not sure if this will work, but you can also try:

Android: noHistory = "true"

Whether the action should be excluded from the action stack and completed (its finish () method is called) when the user moves from it and it is no longer displayed on the screen - "true" if it should be completed, and "false" if not. The default value is false. The meaning of "truth" means that this activity will not leave a historical mark. It will not remain in the action stack for the task, so the user will not be able to return to it. This attribute was introduced in API Level 3.

+1
source

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


All Articles