Android Home key and recent app key processing Onuserleavehint

Source: Internet
Author: User

Compared to the homepage key (home) and the most recent application key (App_switch) processing, the return key is relatively simple, the replication onkeydown can be implemented, as follows:

@Override Public    boolean onKeyDown (int keycode, keyevent event) {        //  keyevent.keycode_home  Keyevent.keycode_app_switch        if (keycode = = keyevent.keycode_back) {            exitaction ();            return true;        } else            return Super.onkeydown (KeyCode, event);    }

Home and App_switch are more complex, especially home keys, which can be exploited by malicious applications if not specifically set. So even if the home button is processed, the measurement will first enter the launcher, a period of time before the execution of our operation, presumably this is also the system layer from a security perspective, there is time to look at the system source code.


After trying many ways, the Onuserleavehint function is more convenient, as follows:

@Override    protected void Onuserleavehint () {        //super.onuserleavehint ();        Exitaction ();    }

The operation is written in the Exitaction function, which takes the startup setting as an example:

private void Exitaction () {        try {            Intent Intent = new Intent ();            ComponentName componentname = new ComponentName ("Com.android.settings",                    "com.android.settings.Settings");            Intent.setcomponent (componentname);            StartActivity (intent);        } catch (Exception e) {            e.printstacktrace ();        }    }

Reprint Please specify source: Zhou Mushi's CSDN blogHttp://blog.csdn.net/zhoumushui 
my github: Zhou Mushi's GitHubHttps://github.com/zhoumushui

Android Home key and recent app key processing Onuserleavehint

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.