我正在尝试创建一个通知,单击该通知会在我的应用程序中显示一条消息,然后当用户单击后退按钮时,我希望它返回到我的主屏幕。
问题是现在它创建了一个全新的实例,并且所有以前的数据都丢失了。我究竟做错了什么?
NotificationManager nm = (NotificationManager) getSystemService("notification");
Intent intent = new Intent(this, beerwarn.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(beerwarn.class);
stackBuilder.addNextIntent(intent);
PendingIntent pIntent = stackBuilder.getPendingIntent
(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(pIntent)
//Notification noti = new Notification.Builder(this)
.setContentTitle("BAC Level Notice")
.setContentText("Your BAC has dropped below Max Legal BAC")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setSmallIcon(R.drawable.beerwarn);
//builder.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(1, builder.build());