这是不正确的!当您从通知开始时,您必须在构建通知时创建堆栈,如下所述:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse
因此,在创建通知时,您必须这样做:
Intent resultIntent = new Intent(this, ResultActivity.class);
// ResultActivity is the activity you'll land on, of course
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent to the top of the stack
// make sure that in the manifest ResultActivity has parent specified!!!
stackBuilder.addNextIntent(resultIntent);
// Gets a PendingIntent containing the entire back stack
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
然后当您单击 UP 按钮时,您需要常规代码,即:
if (NavUtils.shouldUpRecreateTask(this, intent)) {
// This activity is NOT part of this app's task, so
// create a new task when navigating up, with a
// synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(intent)
// Navigate up to the closest parent
.startActivities();
} else {
NavUtils.navigateUpTo(this, intent);
}
这对我来说非常有效。