I need to restore an action instance

Well .. the name is pretty descriptive, I have a bunch of tabs (which I implemented myself, didn’t want to use tabviews with actions inside them), so basically 5 actions called each other every time the user clicks on the tabs displayed as a string LinearLayouts at the bottom of the screen.

The fact is that the way I do it now, every time a user jumps from one action to another, a new action is created and launched. Of course, I see that I spend resources this way. So, what I would like to do is create each action only once; and then, if the user wants to return to the previous one (or to anyone that has already been created and is probably suspended), just check some list or array to see if activity can be restored and only if; to get a new one.

My question is, how can I check this? should i keep my intentions? and how to restore actions after that? I'm kind of new with java.

Hi Nelson R. Perez

+4
source share
2 answers

Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

Set this flag in the intent used to create the activity, and if it exists, it should be moved to the front instead of created again.

+3
source

When your activities are paused or stopped, you must save your activity status in the Bundle (check the activity life cycle)

Then, when your activity begins, you will get access to the Bundle in which you saved your previous state: this is the parameter of the onCreate and onStart methods.

-1
source

Source: https://habr.com/ru/post/1309270/


All Articles