I looked around a lot for an answer but guess i must be missing something obvious…
When a user does a certain operation in my app i wish to display an icon in the bar, aswell as a message in the “messages” dropdown.
This works fine, however, when my app is shut down (through the activity manager), or i restart the phone, all is cleared.
The icon is unavoidable i suppose, but i would like the message to only be cleared when the user clears it, and to be persistent across phone restarts.
Is this possible?
code:
Notification notification = new Notification(icon, message, when);
notification.flags = Notification.FLAG_AUTO_CANCEL;
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "The Message";
Intent notificationIntent = new Intent(this, MyActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
getNotificationManager().notify(STATUSBAR_ID, notification);
This SO answer should help you out on this:
“For raising a
Notification, you can probably get by with just doing it in theBOOT_COMPLETED_ACTIONBroadcastReceiver, rather than delegating it to a service. However, I agree, this is the only way to do it AFAIK.”Android: make notification persist across phone reboot