I am wondering how to save a feature across all pages when flipping between them in Android Studio.
I am trying to make a rigged dice rolling app that I want a setting to stick with the app until I turn it off.
Current code for the page where I want to have the setting save:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showToast(View view) {
Toast toast = Toast.makeText(this, "You've switched a switch", Toast.LENGTH_SHORT);
toast.show();
}
public void changeHomeScreen(View view) {
startActivity(new Intent(getApplicationContext(), HomeScreen.class));
}
public void trollMode (View view){
Switch s = findViewById(R.id.switch3);
ImageView i = findViewById(R.id.imageView2);
Button a = findViewById(R.id.button4);
Button b = findViewById(R.id.button7);
Button c = findViewById(R.id.button8);
Button d = findViewById(R.id.button9);
Button e = findViewById(R.id.button10);
Button f = findViewById(R.id.button11);
a.setVisibility(View.INVISIBLE);
b.setVisibility(View.INVISIBLE);
c.setVisibility(View.INVISIBLE);
d.setVisibility(View.INVISIBLE);
e.setVisibility(View.INVISIBLE);
f.setVisibility(View.INVISIBLE);
if (s.isChecked()){
i.setImageResource(R.drawable.trollface);
Toast toast = Toast.makeText(this, "You have ENABLED Troll Mode!", Toast.LENGTH_SHORT);
toast.show();
MediaPlayer myAudio = MediaPlayer.create(MainActivity.this, R.raw.evillaugh);
myAudio.start();
} else {
i.setImageResource(R.drawable.dices);
Toast toast = Toast.makeText(this, "You have DISABLED Troll Mode", Toast.LENGTH_SHORT);
toast.show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showToast(View view) {
Toast toast = Toast.makeText(this, "You've switched a switch", Toast.LENGTH_SHORT);
toast.show();
}
public void changeHomeScreen(View view) {
startActivity(new Intent(getApplicationContext(), HomeScreen.class));
}
public void trollMode (View view){
Switch s = findViewById(R.id.switch3);
ImageView i = findViewById(R.id.imageView2);
Button a = findViewById(R.id.button4);
Button b = findViewById(R.id.button7);
Button c = findViewById(R.id.button8);
Button d = findViewById(R.id.button9);
Button e = findViewById(R.id.button10);
Button f = findViewById(R.id.button11);
a.setVisibility(View.INVISIBLE);
b.setVisibility(View.INVISIBLE);
c.setVisibility(View.INVISIBLE);
d.setVisibility(View.INVISIBLE);
e.setVisibility(View.INVISIBLE);
f.setVisibility(View.INVISIBLE);
if (s.isChecked()){
i.setImageResource(R.drawable.trollface);
Toast toast = Toast.makeText(this, "You have ENABLED Troll Mode!", Toast.LENGTH_SHORT);
toast.show();
MediaPlayer myAudio = MediaPlayer.create(MainActivity.this, R.raw.evillaugh);
myAudio.start();
} else {
i.setImageResource(R.drawable.dices);
Toast toast = Toast.makeText(this, "You have DISABLED Troll Mode", Toast.LENGTH_SHORT);
toast.show();
}
}
}
This is for the switch called "Troll Mode" which my method is called. I want, when it is switched on, to make buttons appear, and then when you click those buttons, I want it to reroute you to my home page. When you roll the dice on the home page while troll mode is on, then it will only show the number that you picked and nothing else until you turn troll mode off.
If anybody needs more information about the problem, I will be happy to give you what you need to the best of my ability.