1

I start my app through a PendingIntent that comes from a notification and looks likes this:

PendingIntent pendingIntent = PendingIntent.getActivity
    (getApplicationContext(), 1 , intent, PendingIntent.FLAG_ONE_SHOT);

I set an extra so that a specific task is performed and get it via:

GcmListenerService.PushNotificationTrigger pushNotificationTrigger = (GcmListenerService.PushNotificationTrigger) intent.getSerializableExtra(
            GcmListenerService.GCM_PUSH_TRIGGER_KEY);

After the task is performed, I "close" the app via back press (simple onBackPressed). When opening the app again, it performs the task again. I debugged it and came to the result, that the pushNotificationTrigger is still the same. The Intent had the same extras as before I closed it. It seems to me, like Android caches it.

What I already tried and what didn't worked:

Removing the extra, after it was read the first time with:

intent.removeExtra(GcmListenerService.GCM_PUSH_TRIGGER_KEY);

Overriding onBackPressed with finish()

Is there a solution for this?

alexfi
  • 370
  • 2
  • 11
  • press back button just force your activity to go to background, it doesn´t close it. If you want to close it, call finish() in onBackPressed..... – Opiatefuchs Nov 04 '16 at 14:46
  • Thank you for your answer @Opiatefuchs I tried this, but it didn't work either. – alexfi Nov 04 '16 at 14:50
  • ok, not really clear....do you want to have another intent or don´t you want to perform the task again? – Opiatefuchs Nov 04 '16 at 14:53
  • To make it clear: I want to start again in the normal way the activity starts, without having that extra within the Intent. The task should not be performed again, but it does for now. – alexfi Nov 04 '16 at 14:55
  • please show more of your code, from the posted snippet we can´t see the problem.... – Opiatefuchs Nov 04 '16 at 16:47
  • 1
    @Opiatefuchs you are not correct. The default behaviour of `onBackPressed()` is to call `finish()`. This is standard Android behaviour and you do not need to override `onBackPressed()` to call `finishI()`, that is useless. When you press the BACK key, this does NOT put your app in the background, it finishes the current `Activity`. Maybe you should write a simple test program with 3 activities and try it yourself. – David Wasser Nov 06 '16 at 12:26
  • 1
    See my answer in http://stackoverflow.com/questions/19813652/remove-data-from-notification-intent for more information about how to deal with this problem. – David Wasser Nov 06 '16 at 12:27

0 Answers0