我创建了一个广播接收器来创建通知,通过单击启动的活动的通知,该活动正在启动,但我无法查看它,我使用以下代码:
private NotificationManager notificationManager;
@Override
public void onReceive(Context context, Intent intent) {
if (notificationManager == null) {
notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setTicker("Its Ticker")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification Title")
.setContentText("Its Content")
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK),0));
notificationManager.notify("interstitial_tag", 0, builder.getNotification());
}
注意:NotificationDialog.java
是我的活动,此活动正在我调试但未查看时运行。尝试了几个小时但找不到任何答案,任何建议都将受到赞赏。
答案 0 :(得分:0)
使用 FLAG_ACTIVITY_CLEAR_TOP 代替 FLAG_ACTIVITY_CLEAR_TASK
private NotificationManager notificationManager;
@Override
public void onReceive(Context context, Intent intent) {
if (notificationManager == null) {
notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setTicker("Its Ticker")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification Title")
.setContentText("Its Content")
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),0));
notificationManager.notify("interstitial_tag", 0, builder.getNotification());
}