Why do I return to the previous activity when I press backspace on the serchview?

3

I do not understand how it works, I have 3 activities with the same characteristics, all have a listiew, they all have a searchview, one of them works correctly, the detail is when in two of them when I'm in the searchview I press Backspace (delete) does not erase the search if I do not return to the previous activity, to which that event is due, in no time I have made a code that by pressing backspace I return,: S

the detail is when you press the backspace key, in theory you must delete the string that is searched in the listview, end it or return to the parent activity, attach the search view code;

 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_buscar).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);

    SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener()
    {
        @Override
        public boolean onQueryTextChange(String newText)
        {
            ADA.getFilter().filter(newText);
            return true;
        }
        @Override
        public boolean onQueryTextSubmit(String query)
        {
            ADA.getFilter().filter(query);
            return true;
        }
    };
    searchView.setOnQueryTextListener(textChangeListener);
    
asked by Mark Dev 15.08.2016 в 19:42
source

2 answers

2

Check the Activity that closes that you have not implemented the onBackPressed() method and this is calling the finish() method, that may be the cause that causes your Activiy to close:

@Override
public void onBackPressed() {
 ...
 ...
  finish();
}

or the onKeyDown() method that also detects pressing certain keys:

@Override  
    public boolean onKeyDown(int keyCode, KeyEvent event)  {        
         if(keyCode == KeyEvent.KEYCODE_BACK){  
                ...
                ...
                finish();
         }  
         return true;  
   } 

Update:

The NavUtils.navigateUpFromSameTask(this); method that is called within onKeyDown() is the one that produces the closing of the Activity :

  

NavUtils.navigateUpFromSameTask () The source activity is finished   when the call to this method is made.

    
answered by 15.08.2016 в 22:06
0

Well I found the error ....

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    NavUtils.navigateUpFromSameTask(this);
    return super.onKeyDown(keyCode, event);

I had to comment on this method ... which did not have the activity that works, because it may have some logic that the backspace key has that function also in the activities, in android I hope someone else will help you. publication

    
answered by 15.08.2016 в 23:42