3

When a notification is pressed in my app, it goes to the onNewIntent() and the app is processing the extras in the intent. I am not doing setIntent any where in my code.

All is working good except for this weird behavior: If, after the notification was processed, the user presses the back button, which closes the activity) and then in the resent apps menu he presses on my app then the intent that gets to the app is the same intent that came from the push.

Just to be clear, If the user presses on the launcher Icon, it's not happening. It happens only if he presses on the recent apps.

why is that so?

I even tried to do a setIntent with new extras but it's still stuck on the old intent. Why is that and how can I fix this?

Update:

extraMatchId = intent.getStringExtra(StaticParams.KEY_MATCH_ID);
    extraUrl = intent.getStringExtra(StaticParams.KEY_URL);
Dhasneem
  • 4,037
  • 4
  • 33
  • 47
roiberg
  • 13,629
  • 12
  • 60
  • 91
  • Could you add some code examples? – Ricardo Nov 17 '13 at 10:52
  • I added the code from I am taking the extras. – roiberg Nov 17 '13 at 10:55
  • You need to add more than that. An Intent remains the same if you don't update it somewhere. When you press the back button, does this `intent` of yours get updated? – Ricardo Nov 17 '13 at 10:58
  • Accord to the docs, "Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.": http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29 – Ricardo Nov 17 '13 at 11:01
  • As I said, I tries to setIntent with a new intent but the new intent is there until the user presses back. when he gets back using the recent apps the old Intent is in again. Just to be clear, If the user presses on the launcher Icon it's not happening. it happens only if he presses on the recent apps. – roiberg Nov 17 '13 at 11:04
  • Ricardo, Yes, I tried to setIntent. the new intent is not visible when getting back from the recent apps. – roiberg Nov 17 '13 at 11:05
  • Hmmm. Have you tried this? http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmode-singletop – Ricardo Nov 17 '13 at 11:08
  • In my case the Activity is the same instance with the same intent... The question in your link says the a new instance is created. This is not the problem I am having. – roiberg Nov 17 '13 at 11:12

1 Answers1

2

This is either an Android bug or a feature, depending on whether you want it to happen or not ;-) This case isn't clearly documented, but it is clear that it behaves the way you describe.

I recently answered a similar question and made some suggestions about how to deal with this problem. See my answer for more information.

Community
  • 1
  • 1
David Wasser
  • 93,459
  • 16
  • 209
  • 274