我阅读了创建通知的文档。因为他们使用了TaskStackBuilder
:
他们没有使用StackBuilder
对象在NotificationCompat.Builder
对象中设置。他们使用了PendingIntent
对象。
所有上述信息(创建单独的任务,识别父活动,识别意图)都在PendingInent中吗?
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
答案 0 :(得分:0)
在您的应用中使用通知时会发生什么。您首先指定显式意图(正常意图)。然后创建 TaskStackBuilder 对象,以便在点击通知时访问您要启动的活动,然后使用 TaskStackBuilder PendingIntent 引用> getPendingIntent ()并将其传递给通知对象。
现在 PendingIntent 做的是使用 stackBuilder.getPendingIntent(int id,Flag)从 TaskStackBuilder 对象获取意图并传递挂起通过调用 notification.setContentIntent(PendingIntent object)
来通知对象要恢复代码中的错误,请按以下步骤操作: -
我相信你会完成这条指令......
注意: - 通知对象不接受意图对象,它需要 PendingIntent对象。