I am having an issue with my Android app returning to the state it is in whenever it is launched whenever the screen is rotated. The app has several ImageButtons that change their image whenever clicked on, and I have music playing in the background on a loop. Whenever the screen is rotated though, the ImageButtons return to their default image even if they have been changed by the user touching them, and another instance of the music loop starts to play. How can I stop this from happening? I have no idea what to do about the ImageButtons. As for the music loop, I have tried using onStart(), but it continues to happen anyway, even if I use a boolean to check if it has already completed the tasks once.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity);
}
@Override
protected void onStart() {
if(firstRun)
{
super.onStart();
mediaPlayer = MediaPlayer.create(this, R.raw.music);
mediaPlayer.setLooping(true);
mediaPlayer.start();
firstRun = false;
}
}