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 =
.setContentTitle("Bring me front!")
.setContentText("Bring me!!! BRING!!!")
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
A couple of things to check:
FLAG_ACTIVITY_CLEAR_TOP) to ensure that the activity is brought to the front.