About the Android return key code implementation

Source: Internet
Author: User

Transferred from: Http://www.dewen.io/q/11313/android+%E6%A8%A1%E6%8B%9F%E8%BF%94%E5%9B%9E%E9%94%AE%E5%8A%9F%E8%83%BD,

I found that there are two ways to do this.
①, Java.lang.Runtime

    1. Runtime Runtime = runtime. GetRuntime();
    2. Runtime. EXEC("Input keyevent" + keyevent. Keycode_back);

②, Android.app.Instrumentation

    1. Instrumentation Inst = new instrumentation();
    2. Inst. Sendkeydownupsync(keyevent. Keycode_back);

have been tested successfully. You can achieve the effect of pressing back.

Reviews3) • Link 2013-03-20
    • 0 give force, praise a-mottled-neo 2013-03-20
    • 0 very good, thank you for your answer, both methods are feasible, that is, instrumentation is a test environment simulation, do not know my production environment with this has wood problems, there is instrumentation this thing can not be used in the main thread, But open a thread on it, thank you very much –tlchencheng 2013-04-01
    • 0 @tlchencheng Are you sure that you can do this by doing this, and that the return operation is possible in any program interface? –wangqi0609342013-08-04

About the Android return key code implementation

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.