0

My app has launch-mode attribute ="singleTop" in the manifest and handles the intent it was launched by with getIntent(). After handling the intent it calls setIntent(new Intent()); to erase the original intent. This avoids the activity handle the same intent if it is created again (for example if orientation change is managed).

I just have problems when the activity gets destroyed when I press the back button: indeed when I tap on its "recent apps" slot the activity is created again and I get the original intent handled again. No original intent if I call the app again from the home screen.

Note that:

  • the app has to be visible in the "recent apps" menu;
  • the activity can receive further intents (it's "singleTop") and handles them in onNewIntent();
  • if the activity gets destroyed it can be started again with an intent; How to erase the original intent from the "recent apps" slot too?
P5music
  • 3,197
  • 2
  • 32
  • 81
  • Check out this link and see if it helps: http://stackoverflow.com/a/25535915/1970641. I also commented on the accepted answer and you may be interested in reading it. – tato.rodrigo Sep 24 '14 at 12:22
  • This is a known problem/feature. See my answer here: http://stackoverflow.com/a/19820057/769265 – David Wasser Mar 08 '17 at 18:15

1 Answers1

0

You shouldn't do such things like start activity again only to delete activity creation parameter (Intent). This is default Android system behavior to keep Intent with which it was created.

You can bypass this while creating flag boolean dataHandled. After you handle first time intent, set dataHandled = true. Of course don't forget to save this value in onSaveInstanceState call.

protected void onCreate(Bundle savedInstanceState) {
    if(!savedInstanceState.containsKey("dataHandled") {
        //handle IntentData
    }
}

protected void onSaveInstanceState(Bundle outState) {
    outState.putBoolean("dataHandled", true);
    super.onSaveInstanceState(outState);
}
user123
  • 1,053
  • 15
  • 27