Skip to content Skip to sidebar Skip to footer

After Notification Button Return To Original Activity

I wrote an app, that brings up a notification every certain time via an alarmIntent. The user clicks on the notification and gets into an activity. After doing something in this ac

Solution 1:

try adding this lines in your Activity

@OverridepublicvoidonBackPressed() {
    super.onBackPressed();
    Intentintent=newIntent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    finish();
    System.exit(0);
}

Solution 2:

So I found the solution finaly: you need to add the Intent.FLAG_ACTIVITY_MULTIPLE_TASKS flag to the intent as explained in that question: Go back to previous screen on backbutton pressed after responding to notification

Solution 3:

Try Activity.finish() inside the button click listener function. This is similar to pressing the back button.

Solution 4:

There are two types of Activity started by Notification : regular & special. Regular Activity always return to Launcher or your previous activity. Special Activity will return to your Application.

As your description, you should use Regular Activity and get PendingIntent by TaskStackBuilder, it will create an artificial back stack for notification activity.

for example :

PendingIntentresultPendingIntent=
    stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

And this is the document, you can find detail here. http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Post a Comment for "After Notification Button Return To Original Activity"