2

I have implemented gcm Notification's for my android app with PendingIntent which will take user to an Activity when notification will be clicked now, I have defined types of notification's switching user to other's activities and when user press back button app closes which I don't want.

I want is to open LAUNCHER activity always which is defined in manifest when user click back button from an Activity open from Notification. Is there any way to achieve it ? thanks in advance

Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65

1 Answers1

3
Refer this link :
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse

First define Activity hierarchy in AndroidManifest.xml for Launcher activity.Also build your notification as follows :

    <activity
    android:name=".LauncherActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".ResultActivity"
    android:parentActivityName=".LauncherActivity">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".LauncherActivity"/>
</activity>

        Intent resultIntent=new Intent(this,ResultActivity.class);
        TaskStackBuilder stackBuilder=TaskStackBuilder.create(this);
        stackBuilder.addParentStack(ResultActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager mNotif`enter code here`icationManager=
        (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(id,builder.build());
JItesh SUvarna
  • 663
  • 7
  • 17