Answer the question
In order to leave comments, you need to log in
When switching back to the fragment, an error occurs, how to fix it?
Hello, I have a stop button, when I click on play, then I click on stop, the radio broadcasting stops, but there is such a moment, once I accidentally clicked on stop 2 times and the application crashed, how can I handle the event so that when I click 2 nothing did not happen, below is the stop button listener code and the screen
@Override
public void onClick(View view) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer = null;
playPause.setChecked(false);
}
else {
playPause.setChecked(true);
}
}
Answer the question
In order to leave comments, you need to log in
Correct the check:
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question