-1

MainActivity is opened in My app. Consider this scenario,

when MainActivity(1) is currently running. Notification comes, user clicks and Mainactivity(2) gets opened. It works. When I click back button. Mainactivity(2) gets destroyed. MainActivity(1) is shown to user and app freezes. I was looking for a way to close MainActivity(1).

NotificationManagerCompat manager =   NotificationManagerCompat.from(this);

Intent notificationIntent = new Intent(this, MainActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
    | Intent.FLAG_ACTIVITY_NEW_TASK );

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    notificationIntent, 0);

builder.setContentIntent(contentIntent);
manager.notify(123,builder.build());
jeprubio
  • 17,312
  • 5
  • 45
  • 56
Rohaitas Tanoli
  • 624
  • 4
  • 16

1 Answers1

0

I just added "singleTop" in the Manifest file. It worked for both scenarios. When an activity is currently display and App is in the background.

  <activity android:name=".MainActivity"
        android:launchMode="singleTop"></activity>
Rohaitas Tanoli
  • 624
  • 4
  • 16