Android listens to the HOME Key in the simplest way.
Public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000; public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. getWindow (). setFlags (FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED); // key code setContentView (R. layout. main);} Then rewrite the onKey event.
In Android, how does one listen to the Back and Home keys?
Inherit Activity
Override OnKeyDown ()
Print the key value.
It seems to be on different mobile phones. The corresponding key values are different.
Obtain the Back and Home key values.
Then match the key value. Write what you want to do.
Back can be written as follows:
Public boolean onKeyDown (int keyCode, KeyEvent event ){
// TODO Auto-generated method stub
If (keyCode = KeyEvent. KEYCODE_BACK ){
}
Return super. onKeyDown (keyCode, event );
}
Can the android program listen to the home Key in the following ways? If it is feasible, you will receive 100 points.