Android Project Combat (11): Use of the Movetasktoback (Boolean) method

Source: Internet
Author: User

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

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.