title: save the state when back button is pressed
body: <p>I am developing an android app. If I press a back button the state of my application should be saved .What should i use to save the state ..am confused with all of these <code>onPause()</code>,<code>onResume()</code>, or <code>onRestoresavedInstance()</code> ??? which of these should i use to save the state of my application?? For eg when i press exit button my entire app should exit i have used finish() ?</p>
  
  <pre><code>   public void onCreate(Bundle savedInstanceState)
     {   
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      s1=(Button)findViewById(R.id.sn1);
      s1.setOnClickListener(this);
      LoadPreferences();
      s1.setEnabled(false);
      }
  
      public void SavePreferences()
   {
          SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putBoolean("state", s1.isEnabled());
         }
   public void LoadPreferences()
   {
       System.out.println("LoadPrefe");
          SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
          Boolean  state = sharedPreferences.getBoolean("state", false);
          s1.setEnabled(state);
         }
   @Override
   public void onBackPressed()
   {
      System.out.println("backbutton");
      SavePreferences();
       super.onBackPressed();
   }
  </code></pre>