3

I created an example project here:

https://github.com/amitishai/Android-notifications

Here is the scenario:

  1. Open app
  2. Press button
  3. Exit app
  4. Click on the notification that was created. When the app opens you will be in Activity "Bla".
  5. Press the OS BACK button.
  6. Long press the OS Home button in order to see the open apps.
  7. Click on the app.

You will see that you have entered Activity "Bla" again, and the text is the same.

If the activity was initially created with the intent, and then destroyed, how is the intent not null when restarting the activity?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Amit Ishai
  • 621
  • 1
  • 5
  • 8
  • are you sure that `OnDestroy()` is called and not `onPause()`? I think that when the `Back` button is pressed the application is in `onPause`. – g00dy Jun 26 '13 at 14:05
  • onDestroy() is called. I checked. – Amit Ishai Jun 26 '13 at 14:08
  • Ok, then i would guess that this is comming from getStringExtra, as explained: 'Returns -> the value of an item that previously added with putExtra() or null if no String value was found.' So if the Bla Activity was started from `MyActivity.java`- there you have `Intent cit = new Intent(context, Bla.class);` and then `cit.putExtra("string", "please disappear");`. Is it not what you're searching for? – g00dy Jun 26 '13 at 14:26
  • No. When resuming the app, MyActivity is not at all started. The first activity opened is "Bla". – Amit Ishai Jun 26 '13 at 14:29
  • Basically the question is: If both activities are destroyed, how does activity "Bla" have an intent != null when it starts? – Amit Ishai Jun 26 '13 at 14:31
  • Furthermore, why does the "Bla" activity get started rather than "MyActivity" in this scenario? – Amit Ishai Jun 26 '13 at 14:46
  • Please post the code you use to create the notification. Also, when you say "exit app", what do you mean? Are all activities "finished"? – David Wasser Jun 26 '13 at 15:38

1 Answers1

1

The solution was to use Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY Example is here: Android: Starting app from 'recent applications' starts it with the last set of extras used in an intent

Community
  • 1
  • 1
Amit Ishai
  • 621
  • 1
  • 5
  • 8