Handling android back button

155 Views Asked by At

I have a basic question about android development. In my app i have a autocomplete box. When user click on a menu button, autocomplete become visible. When user clicks on an entry in autocomplete, the text views show it. I want to use back button such that when user presses it . Textview become invisible , on again click autocomplte disappears and than on third click app exits. But in my app on a single click app exits. I am a new to development so doesn't know much about it, so i ask here.

1

There are 1 best solutions below

0
On
@Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
       if ((keyCode == KeyEvent.KEYCODE_BACK)) {
         //stuff
       }
    return super.onKeyDown(keyCode, event);
   } 

Since API 5 :

 @Override
    public void onBackPressed() {
        //stuff

    }