Listen to the Android home key problems encountered

Source: Internet
Author: User

Android TV monitor Home key switch source encountered problems

The implementation of the function is to press the home button, focus on the TV Small window, press the home button again, switch the source, into another source. In another source display, press the Home button, the original source view shrinks and displays the current source.

The solution code for this requirement is relatively easy. Implement a Broadcastreceiver and listen to the Home key. However, according to the home key implementation, the system will switch to the current Launcher, so in the case of the current source, click the Home button, The process of walking is:

Onpause->onstop->onrestart->onstart->onresume.

This is a function that exposes us to the ability to make a copy, but there is actually a very important detail hidden here. when executing to Onrsume , the system should be asynchronous to switch avtivity View, that is, display the current default Launcher 's View. Therefore, when switching the source, this time period synchronization can be problematic. That is, when the focus is on the TV Small window, press the Home button

① Android the system switches to the current Launcher ,

② Switch Source, enter TV .

or ②-- . > ①, no access. TV . At this time the current Launcher View will not be redrawn, so it is completely invisible to have switched the source, and then cut back the process.

Previously there was always a Login each of the periodic functions, checking for no anomalies (so the guess is to asynchronously perform The redraw of the View). Then check the Logfor the entire Android system. To redirect on the command line:

adb logcat-v-F time > F:\adblocat.txt .

to view the entire system. Log , found in Activitymanager switch to the current Launcher , thus solving the problem. The method is simple, that is, the new thread in the Broadcastreceiver and sleep for a short period of time to force the system to switch Launcher Before, convert the source behind (i.e. ①-->②) so that it is OK .

Summary, in the multi-application (source) switch, when the external application (jar) more time to look at the logof the system, have seen the problem. To understand the core control, the event should be relatively profound, as far as possible to consider the implementation mechanism, in order to investigate the problem of the location!

Listen to the Android home key problems encountered

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.