在onCreate()
和onPause()
方法之间的某处,我的changePage
布尔值从false
更改为true
,而没有系统地调用它。调用onCreate()
方法后,按下触发onPause()
方法的主页按钮,突然将布尔值更改为true。到底是怎么回事?
public class Menu extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Global.changePage=false;
Global.snd = MediaPlayer.create(getApplicationContext(), R.raw.bgmusic);
Global.snd.start();
Global.btnSound = (ToggleButton) findViewById(R.id.tglSound);
Global.snd.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Global.snd.start();
}
});
}
@Override
protected void onPause() {
super.onPause();
if (Global.changePage){
}
else{
Global.snd.pause();
}
}
Global
类看起来像这样:
import android.media.MediaPlayer;
import android.widget.ToggleButton;
public class Global {
public static MediaPlayer snd;
public static ToggleButton btnSound;
public static Boolean changePage;
}