I am trying to restore an instance of an activity, but it is not passing the variable through eg when I reload the variable it is resetting back to its original value. I know onResume(), onRestorSavedInstanceState and onSavedInstanceState are all running as they are showing in my Logcat. Can anyone explain what I am doing wrong:
private int a;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page2);
        Button btn1 = (Button) findViewById(R.id.button1);      
        btn1.setOnClickListener(listener);  
        if(MainActivity.s1!=null){
        onRestoreInstanceState(MainActivity.s1);
        }
    }
    OnClickListener listener = new OnClickListener() {
        public void onClick(View view) {    
            Intent intent = new Intent(Page2.this, MainActivity.class);
            startActivity(intent);
        }
        };
@Override
protected void onResume(){
    super.onResume();
    a++;
    Log.d("VIVZ", a + "Resume");
}
@Override
        protected void onSaveInstanceState(Bundle outState){
            super.onSaveInstanceState(outState);
            outState.putInt("counter1",  a);
            Log.d("VIVZ", a + " was saved");
            MainActivity.s1=outState;           
        }
@Override
        protected void onRestoreInstanceState(Bundle savedInstanceState){
            super.onRestoreInstanceState(savedInstanceState);
            int a = savedInstanceState.getInt("counter1");
            Log.d("VIVZ", a + " Page 2 was restored");
        }
 
    