Search code examples
androidnotificationsandroid-notificationsandroid-4.2-jelly-bean

Open activity from notification Jelly Bean issue


Just to make it short:

what I need is open an activity, start a countdown, minimize, launch a notification when timer goes to 0 and by tapping the notification go back to the previous state of the activity without creating a new one

what I have is this:

Intent intent = new Intent(ctx, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(ctx, 0, intent, 0);

It works perfectly for android <4.2 but when runs on Jelly Bean, it opens a new instance of the Activity. It seems that Jelly Bean does not recognize none of the flags Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP

How can I make it run for 4.2+ ?


Solution

  • Just set your activity launch mode as

    launchMode="singleTop"