我需要知道这一点,所以我可以删除退出选项。
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
mediaPlayer = MediaPlayer.create(this, R.raw.theme);
mediaPlayer.start();
mediaPlayer.setLooping(true);
}}
答案 0 :(得分:0)
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
Static mediaPlayer mp = MediaPlayer.create(this, R.raw.theme);
mp.start();
mp.setLooping(true);
}}
使用此选项覆盖homekey。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
Toast.makeText(this, "You pressed the home button!", Toast.LENGTH_LONG).show();
mp.pause();
return true;
}
return super.onKeyDown(keyCode, event);
}