此活动开始/停止警报工作完美。但警笛游戏我回到这个活动切换按钮显示开始并点击另一个警笛游戏。这意味着两个警笛游戏。
主要Activity.java
public void onToggleClicked(View view) {
// Is the toggle on?
boolean on = ((ToggleButton) view).isChecked();
if (on) {
mp.start();
mp.setLooping(true);
} else {
mp.pause();
}
}
@Override
protected void onPause() {
super.onPause();
SharedPreferences sp = SirenActivity.this.getSharedPreferences(
"my_settings", MODE_PRIVATE);
SharedPreferences.Editor spEditor = sp.edit();
spEditor.putBoolean("ToggleButton", true);
spEditor.commit();
}
@Override
protected void onResume() {
super.onStart();
SharedPreferences sp = SirenActivity.this.getSharedPreferences(
"my_settings", MODE_PRIVATE);
boolean ToggleButtonState = sp.getBoolean("ToggleButton", true);
}