Original: Android Project Combat (11): Use of the Movetasktoback (Boolean) method
When you develop the program is pressed back button to exit, you certainly do not want him to be so the finish (), then want to put the program back to the background.
(similar to PC-side, you close a browser and you minimize the difference between a browser)
See method: Public Boolean Movetasktoback (Boolean nonroot)
Parameter is a Boolean value
1, false, only takes effect when activity is the task root (that is, the first activity, such as start activity)
2, true, no matter when it will take effect, ignore the above conditions
Note: This method does not change the order of activity in a task, and the effect is basically the same as the home key
---------------------------------------------------------------------------------------
With this method, the OnDestroy () method of the activity is not executed
This will only execute OnCreate () at the first boot time. Will not execute after (as long as the process does not die) OnCreate ()
---------------------------------------------------------------------------------------
For example:
Override the Back button in root activity to respond to an event, and when the back button is pressed, the activity is retired to the background
1 @Override2 PublicBoolean OnKeyDown (intKeyCode, KeyEventEvent) {3 if(KeyCode = =keyevent.keycode_back) {4Movetasktoback (true); 5 return true;6 }7 returnSuper.onkeydown (KeyCode,Event);8}
Android Project Combat (11): Use of the Movetasktoback (Boolean) method