我想在用户点击通知时打开 Activity 。我知道这个问题是重复的,但在这里找不到解决方案是我所做的
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
这里是 documentation我跟着。有人有什么主意吗?为什么 ResultActivity 打不开?
最佳答案
引用此引用链接并获取解决方案。
Start activity once notification clicked
Open application after clicking on Notification
Clicking on Notification is not starting intended activity?
所有这些都包含在点击通知时打开 Activity 的可接受解决方案。
因此,请正确引用它并获得解决您现在发生的问题的结果。
感谢这个问题和 block 所有者和接受的答案提供者。因为它对许多面临此类问题的开发人员很有用。
关于android 如何在用户单击通知时启动 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428325/