I'm doing Quiz in Android Studio. The game is divided into two categories. After passing the first category, the second button (opening the second category) changes the status from setEnable "false" to "true". How to use the SharedPreferenced method in my code that the changes related to the second button (.setEnable) will be saved after closing the application.
Last level of first category
public class win extends AppCompatActivity implements View.OnClickListener{
Button win1;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_winflagi);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
win1 = (Button) findViewById(R.id.winflagi);
win1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v==win1)
{
Intent myIntent = new Intent(win.this, Activity2.class);
myIntent.putExtra("isEnabled", "enabled");
startActivity(myIntent);
}
}
}
- Class containing a buttons for two categories ...
- button3 opened the first category
entrycity opens the second category
public class Activity2 extends AppCompatActivity implements View.OnClickListener{ Button button3; Button entrycity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_2); button3 = (Button) findViewById(R.id.button3); button3.setOnClickListener(this); entrycity = (Button) findViewById(R.id.entrycity); entrycity.setOnClickListener(this); } @Override public void onClick(final View v) { final MediaPlayer mp = MediaPlayer.create(this, R.raw.menu); if (v == button3) { startActivity(new Intent(Activity2.this, flagi1.class)); Bungee.zoom(this); mp.start(); } if (v== entrycity){ Intent intent=getIntent(); String isEnabled = intent.getStringExtra("isEnabled"); if(isEnabled==null||isEnabled.equals("disabled")){ entrycity.setEnabled(false); } else{ entrycity.setEnabled(true); startActivity(new Intent(this, cities1.class)); } } } }