0

onCreate()在and方法之间的某个地方onPause(),我的changePage布尔值从 更改为falsetrue而没有系统地对其进行任何更改。调用该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;
}
4

0 回答 0