Launch application when GCM notification received

jasdmystery picture jasdmystery · Nov 28, 2012 · Viewed 7.9k times · Source

I have GCM notification implementation. I know that the client application receives the notification whether it is in the foreground, background or killed state. What I would like to know is, how can I launch my application on notification received, when the application is in the killed state?

Answer

jasdmystery picture jasdmystery · Jan 22, 2013

In the message receiver, I do the following:

final Intent notificationIntent = new Intent(context, YourActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

Here replace YourActivity.class with the entry activity. This worked for me.