Android - Simulate Home click
I know calling finish() in activity will produce same result as if user clicked on Back button; is there a similar thing for Home button? (would like to automatically sh开发者_StackOverflow社区ow Home screen after certain action).
EDIT: Also, I would appreciate same thing for Menu & Search buttons.
Thanks!
You can simply use an Intent for that:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
HOME:
Intent showOptions = new Intent(Intent.ACTION_MAIN); showOptions.addCategory(Intent.CATEGORY_HOME); startActivity(showOptions);
MENU:
openOptionsMenu(); // this won't work from onCreate // if anyone has idea how it would work // please post it as response
startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
The nearest solution to simulate home click that I found was:
On home button click system log:
I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.belauncher/.ui.activities.MainActivity (has extras)} from uid 1000 on display 0
Simulating intent:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
精彩评论