0

I have an application that receives notification from Google Cloud Messaging. When user click on notification, i must open a special window from notification, so here is part of my app:

gcmintentservice:

            final Intent i = new Intent(this, MapActivity.class);
            i.putExtra("notification",true);
            final PendingIntent contentIntent = PendingIntent.getActivity(
                    this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

This puts extra flag "notification" to intent.

MapActivity.class - onResume():

    if (getIntent().hasExtra("notification")) {
    final Bundle extras = getIntent().getExtras();
    notification = extras.getBoolean("notification");
} else {
    notification = false;
}

Everything works fine, except one condition - when app is resumed from task list somehow "notification" extra is still passed to intent. How to avoid that?

msc3
  • 21
  • 4

2 Answers2

0

When the application is resumed, it is resumed from the state that it was paused from, so if the intent had the extra when it was paused, it will have it when it was resumed.

What you can do is remove the extra from the intent after you have used it:

getIntent().removeExtra("notification"); 

When the application is resumed, the intent will no longer have anything under the "notification" key.

Forb
  • 10
  • 6
  • I already tried that, i added this after `notification = extras.getBoolean("notification");` but it's not working... – msc3 Nov 09 '15 at 13:14
  • Try adding another extra to the intent, `getIntent().putExtra("used", true)` then check that first. `if(!getIntent().hasExtra("used") { notification stuff in here }` – Forb Nov 09 '15 at 13:24
0

Finally, i found solution

At first - https://groups.google.com/forum/#!topic/android-developers/yyd7_8JSwfc It's impossibe to change intent extras that comes from "Recent"

Solution:

        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)!=0) {
        Ln.d("launched from history");
        notification = false;
    }

based on this topic: Remove data from notification intent

Community
  • 1
  • 1
msc3
  • 21
  • 4