I have an Activity
MyActivity. When I start this Activity
, I am showing a Notification
at status bar with the following details.
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());
Say if I kill the app, then notification doesn't disappears. Now if I click the notification, it will come to MyActivity which has null objects everywhere. I have tried killing the activity but it doesn't bother. Any idea how I can kill this activity or if I kill the app, the notification should disappear as well.