When I am out of my app (when pressed home button or back button), the music keeps playing in the background. How can I stop it?
public class MainActivity extends Activity implements OnClickListener {
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ourSong = MediaPlayer.create(MainActivity.this, R.raw.girissong);
ourSong.start();
// codes
}
@Override
public void onClick(View v) {
// some code
}
}
}
I made this code and it should stop when I go to next class and the next song will start