我的布尔值不断从虚假变为真

时间:2013-10-26 10:07:06

标签: java android eclipse adt

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;
}

0 个答案:

没有答案