Android Status Bar Notification: make it un-clearable and have it return to app (not start a new instance)
I found a solution to this problem. I used FLAG_ONGOING_EVENT to make the notification persist. Here's the code:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.mypic;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = "Title Text";
CharSequence contentText = "Content text.";
Intent intent = new Intent(this, MyClass.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
Here is the solution for the NotificationCompat.Builder
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("MyApp")
.setContentText("MyMsg")
.setOngoing(true);
More at the Google docs.