The implementation of the home key function in short is to go back to the desktop, so that activity does not destroy, program background run.
Implementation method:
New Intent (Intent.action_main); Intent.setflags (Intent.flag_activity_new_task); Intent.addcategory ( Intent.category_home); startactivity (Intent);
Here I will rewrite the return key to implement the home key function:
You need to override the OnKeyDown method to monitor the return key
Public BooleanOnKeyDown (intKeyCode, KeyEvent event) { //If the return key if(keycode== keyevent.keycode_back&&event.getrepeatcount () = = 0){ //overriding the Return keyIntent intent=NewIntent (Intent.action_main); Intent.setflags (Intent.flag_activity_new_task); Intent.addcategory (Intent.category_home); StartActivity (Intent); return true; } return Super. OnKeyDown (KeyCode, event); }
Android Learning Summary-Achieve home key function