This example analyzes the way Android listens on the home key. Share to everyone for your reference, specific as follows:
How do I know if the home button is clicked? When doing launcher, look at the source code to find out why
If your activity has these attributes
When the system clicks the Home button, the system sends a intent to the activity w
Android Home Key MonitorAndroid Normal key value can be processed directly in dispatchkeyevent (), but the home key, more special, need to monitor its broadcast separately, and must be dynamic broadcast, its static broadcast is invalid;Requirements: Home key, set Kill yourself, but there are multiple activity in the Ac
is not very good, does not recommend
Method 2:onuserleavehint Method
Copy Code code as follows:
@Override
protected void Onuserleavehint () {
LOG.D ("Aeon", "Onuserleavehint");
Super.onuserleavehint ();
}
This method will be executed before onsaveinstancestate, and this method is more appropriate according to the API explanation.
Method 3:action_close_system_dialogs
Action_close_system_dialogs can be used in radio monitoring
Copy Code code as follows:
The game needs to count the user to exit the game is to press the return key or home, because the return key is their own cocos2dx to do the monitoring, so here say the Android activity listening Home key method, pro-test is available, here to do a backup which is also reference to other people's Code implementation, Path does not remember, if there is similar, hope forgive me ...Here is a way to listen to
This example describes how Android listens to the home key. Share to everyone for your reference, specific as follows:
Will go to Android in the home button listening, many people first reaction to rewrite the corresponding activity of the onkeydown () method, monitoring when the key pressed KeyCode for Keycode_home, carry out their own corresponding processing. Such as:
@Override Public
boolean on
Project used, record, return key what the physical keys use onkeydown monitoring can be, but lock screen key, home button can not, here use Broadcast monitor both state changesIntentfilter Fragment:Mfilter.addaction (intent.action_close_system_dialogs);//home key mfilter.addaction (intent.action_screen_on); Open screen mfilter.addaction (in
One: The difference between the home key monitor and the back key monitor in Android:
(1). In Android, when the home key is pressed, by default the activity of the stop foreground, that is, the activity is set to stop State "onStop ()" Instead of destroying the State "ondestory ()". If you start the activity again, in
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.