Now Notification is implemented in such a way that when I click it, it opens the main Activity of my application. I need to make it so that the notification opens the application as the Task Manager does, i.e. opens the application in that state on the activation on which it was minimized, and if the application is open, then no action is required. Is it possible to implement?
- Only use of one Activity with fragments inside comes to mind. That is, if you already had open information, then it will remain open. Probably, it is necessary to prescribe in this manifesto this Activity to launch in a single copy. - Lucky_spirit
- Not very elegant, considering that the application is already written) - Kosterio
|
1 answer
There are 2 approaches:
1) In each onPause() when onPause() write the name of the last Activity in the preferences, respectively, in the preferences you will always have the name of the last active Activity and when starting the main Activity , you can check the preferences for the desired
2) When you start the application, look into the stack of the launched Activity and pull out your own and activate the last one ( android.permission.GET_TASKS special permissions are required):
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> list=am.getRunningTasks(Integer.MAX_VALUE); for (RunningTaskInfo task : tasks) {//сканируем весь стек if(context.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName())) //blah-blah } |