tags:

views:

287

answers:

2

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 show Home screen after certain action).

EDIT: Also, I would appreciate same thing for Menu & Search buttons.

Thanks!

+5  A: 

You can simply use an Intent for that:

Intent i = new Intent(Intent.ACTION_HOME);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
Romain Guy
I read this as "There's an intent for that" and chuckled a bit :)
alexanderblom
This doesn't seem to work for API 4 (1.6)? There is no Intent.ACTION_HOME ...
kape123
+1  A: 

HOME:

Intent showOptions = new Intent("android.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
kape123