android – searchView onbackpressed problem with the view-ThrowExceptions

Exception or error:

I have problem with back button of an activity that contains searchview I’m focusing on searchview when the activity starts so the keyboard appears so that’s okay with me so the problems is that I need 3 times to press it so I can back to another activity or …. the steps are:

  1. first back button pressed the keyboard disappears that’s fine with me and of course the focus gone

  2. the search button disappears and autogenerates 3 dots on the right side of the toolbar without a job

  3. back to the other activity or …..

I tried intent in backpressed method still I need to click 3 times to exit the activity
so what I want if is it possible to get back by pressing once or maximum twice not 3 times and why the 3 dots appears..?

 public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(, menu);

    searchItem = menu.findItem(;
    searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        public boolean onQueryTextSubmit(String query) {
            return false;

        public boolean onQueryTextChange(String newText) {

            return false;
    return true;
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *