The usage and function of moveTaskToback to the background, and the background of movetasktoback
1
Method: public boolean moveTaskToBack (boolean nonRoot)
This method is available in activity. The parameters are described as follows:
NonRoot = false → it takes effect only when the activity is the task root (that is, the first activity, for example, starting the activity ).
NonRoot = true → ignore the preceding restrictions
This method does not change the activity sequence in the task, and the effect is basically equivalent to the home Key.
Application scenarios:
For example, if you do not want to exit the activity when you press the return key (finish by default), you can call this method only when you want to set the background.
2
MoveTaskToBack () method: Call moveTaskToBack (boolean
NonRoot) method to return the activity to the background, note that it is not finish () to exit.
Parameter description:
If the parameter is false, it indicates that the current activity is the task root and is effective only when the application starts the first activity;
If the parameter is true, this restriction is ignored. Any activity can be valid.
Determines whether the Activity is the task root. The Activity itself provides the related method: isTaskRoot ()
After moveTaskToBack is called, the activity sequence in the task will not change. For example, if A starts B and B calls this method back to the background, restarting the application will call the onRestart-onStart-onResume method in B, onCreate will not be called again, and A is returned by pressing the back key in B. This is the function to return to the background.
3
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { moveTaskToBack(true); return true; } return super.onKeyDown(keyCode, event);}