From my first activity:
musicGroup = (RadioGroup) findViewById(R.id.radioGroupForMusic);
turnOn = (RadioButton) findViewById(R.id.radioButtonMusicOn);
turnOff = (RadioButton) findViewById(R.id.radioButtonMusicOff);
musicGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(turnOff.isChecked()) {
int musicOff = 0;
mediaPlayer.pause();
Intent intent = new Intent(MainMenuActivity.this, HighScoreActivity.class);
intent.putExtra("music off",musicOff);
startActivity(intent);
}
else if(turnOn.isChecked()) {
int musicOn = 1;
mediaPlayer.start();
Intent intent = new Intent(MainMenuActivity.this, HighScoreActivity.class);
intent.putExtra("music on",musicOn);
startActivity(intent);
}
}
});
and this is my second activity:
Intent intent = getIntent();
int musicOn = intent.getIntExtra("music on",0);
if(musicOn==1) {
mediaPlayer = MediaPlayer.create(HighScoreActivity.this,R.raw.song);
mediaPlayer.setLooping(true);
mediaPlayer.start();
}
At the moment, when I choose whatever radio button
, it will navigate to my second activity, which is not what I want, I just want to control the background music from the first activity and make it effects on other activities. I think I should not use Intent
as it will always navigate to second activity
Thanks for any suggest.