Reputation: 364
Correct me if i am wrong "moveTaskToBack(false/true);" has nothing to do with the visibility of the Activity ,but has everything to do with Activity Stack,because many times on stackoverflow i find people being confused on this.
Now My Scenario: there are two activites A and B A is the root Activity B is launched from activity A
the thing is i don't want my activity B to be killed after the back button is pressed,(just i want it to be invisible,and activity A to be visible which will happen on its own )so that i can restore its state afterwards.
so after searching a bit i came to know about moveTaskToBack(false);, which seemed to be the solution as it does not kill the activity (because the activity is not sent to back in the activity stack),but the only problem is.it works with Root Activity,and hence it will not work in my case.So is there any alternative which i can use with"non-root" activities,so that the state of Activity is restored....
Upvotes: 2
Views: 259
Reputation: 133560
I guess you have misunderstood
public boolean moveTaskToBack (boolean nonRoot)
Added in API level 1
Move the task containing this activity to the back of the activity stack. The activity's order within the task is unchanged.
Parameters
nonRoot If false then this only works if the activity is the root of a task; if true it will work for any activity in a task.
Returns
If the task was moved (or it was already at the back) true is returned, else false.
Back Button by default takes you back to the previous activity. It pop's the activity from the back stack and the previous activity in the stack takes focus.
Save the state of the activity in onPause
restore it in onCreate
or onResume
. To store values persistently chekc the below link for storage options.
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/guide/components/tasks-and-back-stack.html
You may want to check the answer by commonsware in the below link.
https://groups.google.com/forum/#!topic/android-developers/4Pz6LrzVpx0
Upvotes: 1