Answer the question
In order to leave comments, you need to log in
When I press the button 2 times, it crashes, how to fix it?
Hello, I have a button that is responsible for stopping the playback of the radio. The problem is that when I click on it 2 times, it crashes out of the application, how can I paint an event or do I need to write some kind of method? Thanks in advance
Button
@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
Wrap in try/catch and when pressed a second time, display the message "The player has already been stopped"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question