0

I am developing an application in API level 2.2. In my application whenever I press Home button it forces my app to exit, and when I relaunch that app by clicking on its icon, it starts from where it exited. I have tried to change/ override functionality of Home button but it does not works. I have tried as `

public boolean onKeyDown (int keyCode, KeyEvent event){
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            startActivity(new Intent(CategoryFirstActivity.this,LastActivity.class));
            finish();
        }
        else if (keyCode == KeyEvent.KEYCODE_HOME)
        {
            startActivity(new Intent(CategoryFirstActivity.this,LastActivity.class));
            finish();
        }
        return false;
    }`

But it works for Back button only and not for Home button. I have also tried to get keyCode of Home key but I didn't get it. I need solution to change Home Button functionality.

Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
developer
  • 1
  • 2
  • Home Button is a system button. How could you change that functionality ? You can experiment with the Home sample app in your SDK. – sjain Sep 23 '13 at 07:39
  • Ok.. We cann't change functionality, but I want to make my application to terminate totally on clicking Home button so that when I relaunch it by clicking on its icon it starts from beginning or fist activity. – developer Sep 23 '13 at 07:53

2 Answers2

2

Simply put: better you do not change the behavior of your home button...

Zordid
  • 10,451
  • 11
  • 42
  • 58
0

Instead of trying to reprogram your Home button, you could try using some of the Activity callbacks that Android provides. You can take a look at the Activity lifecycle here:

http://developer.android.com/reference/android/app/Activity.html

For example, you could try overriding the onPause callback in an effort to achieve the effect you're going for.

@Override
public void onPause() { /* do stuff */ }

In your case, do stuff might be returning the application to its initial state or forcing it to exit. I've never attempted a force quit myself, but there are some answers on this StackOverflow post:

How to exit from the application and show the home screen?

Best of luck!

Community
  • 1
  • 1
indy
  • 3
  • 2