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