Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Simulate Home click

Tags:

android

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!

like image 741
nikib3ro Avatar asked May 02 '10 03:05

nikib3ro


People also ask

How to simulate notch on Android devices?

These action are fully customizable - you can set swipe and tap duration, repeat interval, repeat count and randomize coordinates. You can see simulate Notch in Android Pie devices at the upper right corner side. You can extract .apk files via ADB.

How do you simulate a touch on a screen?

To simulate a touch at specific screen coordinates from keyword tests, use the Device Touch operation: To simulate long press, swipe and drag actions in keyword tests, call the appropriate methods of the Device object by using the Call Object Method , … It just showed a black screen with no apparent progress.

How to trigger button click event through code in Android?

Just to clarify what moonlightcheese stated: To trigger a button click event through code in Android provide the following: private Button btn; btn = (Button)findViewById (R.id.button2); btn.performClick (); where button is the reference variable of Button class and defined as follows:-

What is the difference between callonclick() and performclick() in Android?

Android's callOnClick () ( added in API 15) can sometimes be a better choice in my experience than performClick (). If a user has selection sounds enabled, then performClick () could cause the user to hear two continuous selection sounds that are somewhat layered on top of each other which can be jarring.


3 Answers

You can simply use an Intent for that:

Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
like image 54
Romain Guy Avatar answered Oct 09 '22 08:10

Romain Guy


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
like image 33
nikib3ro Avatar answered Oct 09 '22 09:10

nikib3ro


startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
like image 5
hrules6872 Avatar answered Oct 09 '22 10:10

hrules6872