MediaPlayer player = MediaPlayer.create(context, R.raw.background);
player.start();
The Code above is part of the current code. When I press the home key, MediaPlayer does not stop playing.
@Override
public boolean onKeyDown(int KeyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (KeyCode == KeyEvent.KEYCODE_BACK) {
System.exit(0);
return true;
}
}
return super.onKeyDown(KeyCode, event);
}
I've implemented the code shown above, for when you press the Back key. Do you think that the above code is correct? Appreciate any help.