我有Activity
MyActivity 。当我开始Activity
时,我在状态栏中显示Notification
,其中包含以下详细信息。
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_app_notify)
.setContentTitle(getString(R.string.app_name))
.setContentText(notificationText)
.setColor(Color.parseColor("#981A75"))
.setAutoCancel(true);
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setClass(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(HomeActivity.class);
stackBuilder.addNextIntent(intent);
notificationBuilder.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
假如我杀了应用,那么通知就不会消失。现在,如果我点击通知,它将变为 MyActivity ,其中包含空对象。我曾试图杀死这项活动,但它并没有打扰。任何想法我如何杀死这个活动或如果我杀了应用程序,通知也应该消失。