0

I'm setting an activity, Receiver, as the content intent for a notification.

Intent clickIntent = new Intent(context, Receiver.class);
            mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT));

Inside Receiver Activity, I'm starting activities which are intended to be opened using TaskStackBuilder in the following way.

Intent intent = new Intent(this, Class.forName(className));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       TaskStackBuilder.create(this).addParentStack(Class.forName(className)).addNextIntent(intent).startActivities();

When the app is in the background and a notification click happens, it resumes the ParentActivity. Especially when device goes to idle and comes back. Any help? I'm cracking my head on this.

madhu
  • 744
  • 3
  • 8
  • 19

1 Answers1

0

For an Android app, you should also declare android:launchMode in your androidManifest.xml file.

As discussed in the Android documentation:

An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent.

They are:

  • "standard"
  • "singleTop"
  • "singleTask"
  • "singleInstance"

The default mode is "standard".

Solution given in this SO post - resuming an activity from a notification might also help.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22