title: How to save state of searchView when orientation is changed
body: <p>I have a searchView in an activity. the search filter is working great and all but there is a problem that I don't know how to resolve. You see when I change orientations from portrait to landscape it cause an error that I don't know what is I'm doing wrong. So can  anyone tell me what I'm doing wrong?</p>
  
  <p>here is the code</p>
  
  <pre><code> ArrayList&lt;petbook_getItem&gt; bookItem=new ArrayList&lt;&gt;();
  RecyclerView petbook;
  petbook_adapter adapter;
  LinearLayoutManager linearLayoutManager;
  TextView pet_title;
  private static Parcelable pet_recycler;
  SearchView searchView;
  private static final String SEARCH_KEY = "search";
  String mSearchString;
  MenuItem searchItem;
  
  if(savedInstanceState != null){
             mSearchString=savedInstanceState.getString(SEARCH_KEY);
          }
  
          pet_title=(TextView)findViewById(R.id.pet_book_title);
          petbook=(RecyclerView)findViewById(R.id.pet_book_pet);
          navbot=(BottomNavigationView) findViewById(R.id.petbook_navbot);
          toolbar=(Toolbar)findViewById(R.id.petbook_toolbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setDisplayShowTitleEnabled(false);
          toolbar.setTitle("");
          linearLayoutManager=new LinearLayoutManager(this);
          petbook.setHasFixedSize(true);
          petbook.setLayoutManager(linearLayoutManager);
          refresh();
          disableShiftMode(navbot);
  petbook.addOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                  if (dy &gt; 0 &amp;&amp; navbot.isShown()) {
                      navbot.setVisibility(View.GONE);
                  } else if (dy &lt; 0 ) {
                      navbot.setVisibility(View.VISIBLE);
  
                  }
              }
          });
      }
  
   @Override
      public boolean onOptionsItemSelected(MenuItem item) {
         if(item.getItemId()==android.R.id.home){
             {
                 finish();
             }
  
         }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          MenuInflater menuInflater= getMenuInflater();
          menuInflater.inflate(R.menu.petbook_searck,menu);
          searchItem=menu.findItem(R.id.pet_book_search_mode);
          searchView =(SearchView)MenuItemCompat.getActionView(searchItem);
          if (mSearchString != null &amp;&amp; !mSearchString.isEmpty()) {
              searchItem.expandActionView();
              searchView.setQuery(mSearchString, true);
              searchView.clearFocus();
          }
          search(searchView);
          MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
              @Override
              public boolean onMenuItemActionExpand(MenuItem item) {
                  pet_title.setVisibility(View.INVISIBLE);
                  return true;
              }
  
              @Override
              public boolean onMenuItemActionCollapse(MenuItem item) {
                  pet_title.setVisibility(View.VISIBLE);
                  return true;
              }
          });
          return true;
      }
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          mSearchString = searchView.getQuery().toString();
          outState.putString(SEARCH_KEY, mSearchString);
      }
     @Override
      public void onPause() {
          super.onPause();
          pet_recycler = petbook.getLayoutManager().onSaveInstanceState();
  
      }
      @Override
      public void onResume()
      {  //
          super.onResume();
          if (mSearchString != null &amp;&amp; !mSearchString.isEmpty()) {
              searchItem.expandActionView();
              searchView.setQuery(mSearchString, true);
              searchView.clearFocus();
              adapter.filterSearch(newList);
              adapter.notifyDataSetChanged();
          }
          else
          {
              bookItem.clear();
              refresh();
          }
          petbook.getLayoutManager().onRestoreInstanceState(pet_recycler);
      }
  
      public void search(android.support.v7.widget.SearchView search)
      {
          search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String newText) {
                  newText=newText.toLowerCase();
                  newList=new ArrayList&lt;&gt;();
                  for(petbook_getItem items : bookItem){
                      String pets=items.getPet_name().toLowerCase();
                      if(pets.contains(newText))
                          newList.add(items);
                  }
                  adapter.filterSearch(newList);
                  adapter.notifyDataSetChanged();
                  return true;
              }
          });
      }
  </code></pre>
  
  <p>here is the error that occurs</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: petguide.com.petguide101, PID: 25230
                java.lang.RuntimeException: Unable to resume activity {petguide.com.petguide101/petguide.com.petguide101.petbook.pet_book}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setQuery(java.lang.CharSequence, boolean)' on a null object reference
                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3226)
                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3257)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2600)
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4210)
                    at android.app.ActivityThread.access$900(ActivityThread.java:178)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1476)
                    at android.os.Handler.dispatchMessage(Handler.java:111)
                    at android.os.Looper.loop(Looper.java:194)
                    at android.app.ActivityThread.main(ActivityThread.java:5631)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
                 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setQuery(java.lang.CharSequence, boolean)' on a null object reference
                    at petguide.com.petguide101.petbook.pet_book.onResume(pet_book.java:197)
                    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1267)
                    at android.app.Activity.performResume(Activity.java:6178)
                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3211)
                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3257) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2600) 
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4210) 
                    at android.app.ActivityThread.access$900(ActivityThread.java:178) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1476) 
                    at android.os.Handler.dispatchMessage(Handler.java:111) 
                    at android.os.Looper.loop(Looper.java:194) 
                    at android.app.ActivityThread.main(ActivityThread.java:5631) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
  </code></pre>