保存实例后,我需要共享“int audio”到 check() 方法来执行几个操作。我有一个“信息”选项:当我点击我看到信息对话框并且我想听音频(当我点击“取消”时停止它)。但是当我旋转模拟器时,我有另一个音频明星。
int audio;
static int Info;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
int Info = savedInstanceState.getInt("dialoginfo");
int audio = savedInstanceState.getInt("audio");
}
if(Info != 0)
{
Info();
}
private void Info(){
Info = 1;
sobCheck();
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.info, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view).create();
TextView text=(TextView) findViewById(R.id.infoView1);
builder.setCancelable(false);
builder.setPositiveButton("Chiudi", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Info = 0;
mp.stop();
mp.reset();
mp.release();
mp = null;
audio = 0;
dialog.cancel();
}
});
builder.show();
}
private void sobCheck(){
if (audio == 0){
mp = MediaPlayer.create(this, R.raw.sob);
mp.start();
audio = 1;
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("audio", a);
旋转屏幕后,“音频”始终为“0”