0

I have an application that implements two activities. Activity A is for selecting some files on device and activity B is to show additional info while these files are processing. Both of them have singleInstance as launch mode.

On application's start activity A runs. Then this activity starts second activity B, that creates a notification. If I tap this notification or open running app from recents, it works fine and shows running activity B. But if I'd started application before and activity B is already running, launching it again from app menu causes showing activity A when old activity B is already running and accesible from notification bar.

So, what should I do to make application run only single activity at the same time and show second activity when called from launcher (if second activity once started and isn't finished)?

  • Do you mean that you open activity B, exit the app, come back to it and activity A opens ? Can you show us your source code, mostly the way you call activity B from activity A, the way you notify user and the PendingIntent is handled ? – Alexandre Martin Jun 29 '16 at 11:09
  • Yes, activity A opens when I open app from launcher (e.g. homescreen shortcut), when I have to see activity B. To start activity B I'm just making an Intent, set it's action as ACTION_VIEW, put some extras and call startActivity(). – Miles Seventh Jun 29 '16 at 11:42

1 Answers1

0

Your launcher intent should be mapped to a dummy activity, with no view (or may be a splash who knows !). In onCreate of that dummy activity you check if a state was saved previously and based on the state switch to the desired activity.

And how to set the state ? well lets try something simple. lets say when Activity A resumes we put "A" to some key in SharedPreference. if Activity B resumes we put "B" to the same key in preferences. Now your application goes out when Activity B was visible, the state saved would be "B", you launch from home screen, the dummy activity finds "B" in the state and launch intent to go to B else go to A.

dumb_terminal
  • 1,815
  • 1
  • 16
  • 27