Search code examples
androidandroid-homebutton

Android Home button click ignoring saved state?


Can I ignore the previous stage of application after tapping Home button in android? So that I can get the application from initial screen.


Solution

  • Use like this.If now you are in LastActivity and you want to go back to the First Activity and there is more activity in between then if you want to go first from last use

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if(autoSearch)
            if (keyCode == KeyEvent.KEYCODE_HOME) {
               Log.d("click","HOMEButtonclicked");
              LastActivity.this.startActivity(new Intent(LastActivity.this, FirstActivity.class));
               moveTaskToBack(false);
               return true;
            }
            return super.onKeyDown(keyCode, event);
        }