NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,"Details", System.currentTimeMillis());
RemoteViews remoteView = new RemoteViews(getPackageName(),R.layout.custom_notification);
remoteView.setImageViewResource(R.id.icon, R.drawable.icon);
remoteView.setTextViewText(R.id.Mesg, "Status : "+ details);
notification.contentView = remoteView;
Intent notificationIntent = new Intent(context,Form.class).putExtra("layout", "99");
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,Notification.FLAG_AUTO_CANCEL);
notification.contentIntent = contentIntent;
notification.flags = Notification.FLAG_AUTO_CANCEL+ Notification.FLAG_ONLY_ALERT_ONCE;
manager.notify(45, notification);
并在我创建我的应用程序时使用
Intent i = getIntent();
k = Integer.parseInt(i.getStringExtra("layout"));
Log.i(TAG, ">>>>>>>>>>" + k);
if (k == 99) {
finish();
}
这将检查您的活动是否仍然存在。如果活动被杀死或关闭,它将带您进入堆栈顶部的活动。如果应用程序完全关闭,它不会做任何事情