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());
The NotificationManager has the (undocumented) behavior that it will ignore the fullScreenIntent field if you post a new Notification that matches the ID of one that's already active.
I had a similar problem. In my case I missed two things:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With