How I can change working of home button in android? I want to when I click on home button I do some actions and after that application should go to background. How I can do that.
Asked
Active
Viewed 5,929 times
1
-
You want your action to happen only when you click on the home button, or any time your application should go to the background ? – Dany Y Jan 06 '13 at 14:28
-
2Take a look at this [post](http://stackoverflow.com/questions/4783960/call-method-when-home-button-pressed-on-android) – atomman Jan 06 '13 at 14:28
-
every time when click home button – user1302569 Jan 06 '13 at 14:30
3 Answers
4
Write your own home screen. When the user presses HOME, they will get a choice of running your app or the built-in home screen. They can elect to choose one just this one time, or set either app as being their default from now on. Many will wonder why on Earth you decided to decided to implement a home screen.
Most developers care about any case where their activity moves to the background, in which case you can either use a lifecycle method (e.g., onPause()
, onStop()
) or try onUserLeaveHint()
.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
0
Have you tried overriding onKeyDown()
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
// ENTER CODE HERE
return true;
}
return super.onKeyDown(keyCode, event);
}

djunod
- 4,876
- 2
- 34
- 28

Yauraw Gadav
- 1,706
- 1
- 18
- 39
0
I do it this way:
/* Handles item selections */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//You can do whatever you want here
Intent homeInt = new Intent(this, SomeActivity.class);
startActivity(homeInt);
return true;
}
return false;
}

Booger
- 18,579
- 7
- 55
- 72