当通知出现并且用户单击它时,DetailsActivity应该启动,然后,如果用户单击后退按钮它应该进入MainActivity,我的问题是它在Android虚拟设备(API 28)上可以正常使用,但是它没有当用户单击通知并启动DetailsAcitivty时,如果用户单击后退按钮,则应用程序的行为就像按下主屏幕按钮并关闭应用程序一样在我的手机上运行(Huawei Honor 8 LITE Android 8.0.0 API 26)。在AVD上,当我单击“后退”按钮时,它将按原样启动MainAcitivty。
NavigationController
清单
public void sendNotification(View v){
public static final String EXTRA_ITEM_ID = "letter_id";
long itemId = 12345678910L;
int notificationId = ((Long)itemId).intValue();
Intent resultIntent = new Intent(this, DetailsActivity.class);
resultIntent.putExtra(EXTRA_ITEM_ID, itemId);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(DetailsActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this,App.NOTIFICATION_CHANNEL_ID_1)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Title")
.setContentText("Notification text")
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentIntent(resultPendingIntent);
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notification);
}
我不知道是什么问题,它可以在AVD上运行