Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Going to home screen programmatically

I want to go to the home screen programmatically in Android when the user clicks on button. How can this be done?

like image 312
Sri Sri Avatar asked Sep 16 '10 07:09

Sri Sri


People also ask

How to Click home button programmatically in android?

addFlags(Intent. FLAG_ACTIVITY_CLEAR_TASK); Now when you pressed the back button being MainActivity the active one, it will go to home screen.

How to go on home page in android?

Go to Home screenSwipe up from the bottom of the screen. Tap Home or Home .

How do I close a program in android programmatically?

use 'System. exit(0);' when you really want to exit the app.


1 Answers

You can do this through an Intent.

Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startMain); 

This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed if the user does not expect this.

If you want this to build an exit button from your app please read this article on exit Buttons in Android

like image 130
Janusz Avatar answered Oct 02 '22 15:10

Janusz