The example in this article describes how Android programming simulates the Home key feature. Share to everyone for your reference, specific as follows:
Do a similar to QQ press the return key does not destroy the activity method (that is, do not call Activity.finish (), the system does not call OnDestroy), but is similar to pressing the home key, let the activity resemble "pause" (that is, call only OnPause, OnDestroy).
The code is as follows:
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = keyevent.keycode_back) {
Intent Intent = new Intent (intent.action_main);
Intent.setflags (Intent.flag_activity_new_task);/Pay attention to
Intent.addcategory (intent.category_home)
; This.startactivity (intent);
return true;
}
Return Super.onkeydown (KeyCode, event);
}
Special attention: intent.setflags (intent.flag_activity_new_task); This must be added because the launchmode of the activity is performed by default standard, and if you do not add this tag, a new activity is created and placed in the same task as the current activity. The following is a description of the Flag_activity_new_task flag_activity_new_task tag
When the intent object passed to StartActivity () contains the flag_activity_new_task tag, the system looks for tasks that are different from the current activity for the activity that needs to be started. If the affinity property of the activity being started is not the same as the Affinity property of all current tasks, the system creates a new task with that affinity attribute and presses the activity to be started on the new task stack; The activity presses into the same stack as the Affinity property.
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android debugging techniques and common problems solution summary", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary
I hope this article will help you with the Android program.