我试图让我的通知构建器仅在被触发的Intent上调用OnResume()
,类似于用户从后台运行的应用程序中选择应用程序时。我尝试了很多旗帜,但我没有得到我想要的结果。
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
Intent intent = new Intent(this, MainActivity.class);
intent.setAction("OPEN_TAB_CONTACTS");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
mBuilder.setSmallIcon(R.drawable.antartica7);
mBuilder.setContentTitle("Notification Alert, Click Me!");
mBuilder.setContentText("Hi, This is Android Notification Detail,WEWWW!");
mBuilder.setContentIntent(pIntent);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify("newmessage", 1, mBuilder.build());
我尝试过添加
android:launchMode="singleInstance"
和
android:launchMode="singleTask"
也是AndroidManifest。
答案 0 :(得分:1)
由于没有标志正在运行,我改为检查Intent动作是手动的。
将此添加到onCreate()
:
if(getIntent().getAction() != null) {
if(getIntent().getAction().equals("OPEN_TAB_CONTACTS")) {
System.out.println("Pending intent called");
} else {
//normal onCreate
}
}