When user click on a notification, I set up a backstack of Activities A -> B, where B is on top and shown to user. I would like the lifecycles of Activity A to run, so that when user presses back button and comes to Activity A, it is already ready. What could I do to achieve this?
Asked
Active
Viewed 262 times
4
-
1I cannot see that is possible, because the way that system gives us ability to launch a stack of activities is `TaskStackBuilder` and that won't make all of the activities on the stack to reach their `onResume()`, because obviously those activities have not yet been displayed to user, only the topmost activity will reach `onResume` state. As soon as you navigate back to previous activity - only then the activity will be created and reach `onResume` state. I think you should reconsider your app logics. What use-case you have? – azizbekian Aug 08 '19 at 06:56
-
Can you give some concrete examples of what you want to preload? – charles-allen Aug 11 '19 at 08:31
-
seems like a resource intensive app? – danny117 Aug 13 '19 at 13:54
2 Answers
4
This cannot be possible as android will not allow us to do that, the only way I can see you can achieve this by doing your Activity A operation inside your Activity B And provide those details to Activity A when the user pressed back button.
Note: If you are showing any kind of list on Activity A or doing similar kind of work, you can have one Singleton Class where you can get your data in Activity B which required by Activity A, and provide same data to Activity A when the user pressed back button.

Jitesh Mohite
- 31,138
- 12
- 157
- 147
0
You should open the activity as normal but then put this line of code in the OnCreate() method to bring to the back.
moveTaskToBack(true);

Abdulrahman Abdelkader
- 64
- 2
- 11
-
-
this will move the activity to the back ground processing. It will be open but in background. You should put this line of code in the activity that you want to run in the background – Abdulrahman Abdelkader Aug 08 '19 at 03:58