The usage and function of moveTaskToback to the background, and the background of movetasktoback

Source: Internet
Author: User

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);}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.