I have two buttons in application with default color WHITE . When I click on first button it's color change to GREEN then I click second button it's color change to RED and button one to WHITE . It works fine but when I start application again color of both button is WHITE . What I want to do is retrieve previous button state . For example previously if I clicked button one then after start application again color of button one already become GREEN .
JAVA Code:
package com.example.pratik.sf2020;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Pattern extends AppCompatActivity {
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pattern);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
b1 = (Button) findViewById(R.id.mp1n);
b2 = (Button) findViewById(R.id.mp1o);
b1.setBackgroundColor(Color.WHITE);
b2.setBackgroundColor(Color.WHITE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
b1.setBackgroundColor(Color.GREEN);
b2.setBackgroundColor(Color.WHITE);
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
b1.setBackgroundColor(Color.WHITE);
b2.setBackgroundColor(Color.RED);
}
}
});
}
}