Anhayt Ananun Anhayt Ananun - 1 month ago 11
Android Question

setFullScreenIntent does not work second time

I have an application in android and I want to bring an activity to foreground in some cases. I use NotificationManager for this. Here is my code. The problem is, activity is brought to front successfully at first time, but then it does not. Also, this code is run from service.

Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent)
.setContentTitle("Bring me front!")
.setContentText("Bring me!!! BRING!!!")
.setFullScreenIntent(contentIntent, true);

NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

Answer

A couple of things to check:

  1. Your intent will probably need FLAG_ACTIVITY_NEW_TASK (and possibly FLAG_ACTIVITY_CLEAR_TOP) to ensure that the activity is brought to the front.
  2. Be sure you're not trying to reuse the same PendingIntent more than once; each time you post this Notification you'll need to construct a new PendingIntent for use with fullScreenIntent.