我有一个通知,当我选择它时,它会使用
然而,如果我从最近打开的应用程序中删除我的应用程序(或者通知在抽屉中停留很长时间),则会出现以下情况:
当我在抽屉中有多个通知时,第一个通知可以正常打开。但是,在点击第二个通知后,我的
onReceive(接收)
PendingIntent
向BroadcastReceiver
发送一个Broadcast
。在onReceive
中,我启动一个新的Activity
。然而,如果我从最近打开的应用程序中删除我的应用程序(或者通知在抽屉中停留很长时间),则会出现以下情况:
当我在抽屉中有多个通知时,第一个通知可以正常打开。但是,在点击第二个通知后,我的
onCreate()
和onResume()
都没有被调用,好像startActivity()
根本不起作用。如果我添加标志Intent.FLAG_ACTIVITY_SINGLE_TOP
,那么将调用onNewIntent
。notificationIntent = new Intent();
notificationIntent.setAction(AppConstants.ACTION_ACTIVITY);
notificationIntent.putExtra("key", value);
int requestID = (int) System.currentTimeMillis();
mBuilder.setContentIntent(PendingIntent
.getBroadcast(context, requestID, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
onReceive(接收)
Intent intent = new Intent(context, Activity.class);
intent.putExtra("key", value);
//IF I ADD FLAG_ACTIVITY_SINGLE_TOP IT WORKS
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Activity
是LAUNCHER
和MAIN
Activity 吗? - ρяσѕρєя KFLAG_ACTIVITY_SINGLE_TOP
? - user1163234