How do I keep my Android notification displayed until my app is closed?

3.2k views Asked by At

I've been developing for Android for awhile but this is my first shot at notifications. I've got my notification setup as described in the Android SDK tutorial, but I can't figure out how to keep the notification displayed until my app is closed. I want to disable that little minus sign at the end of the notification. I don't want my notification to disappear when a user clicks it. I would think there would be a notification flag... but I can't seem to figure this out. I'm developing on Android SDK 2.2. I know this is a simple question, and I apologize if this answer is already on here... I wasn't able to find exactly what I was looking for.

    // Create notification manager
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    Notification notification = new Notification(R.drawable.ic_launcher, "Ready", System.currentTimeMillis());
    Intent notificationIntent = new Intent(this, HomeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    // Make a notification
    notification.setLatestEventInfo(getApplicationContext(), "Ready", "Select to manage your settings", contentIntent);
    mNotificationManager.notify(0, notification);
1

There are 1 answers

2
jnnnnn On BEST ANSWER

You want FLAG_ONGOING_EVENT. Also try removing FLAG_NO_CLEAR and FLAG_AUTO_CANCEL if they are part of the defaults.