当我的游戏显示暂停alertdialog并且屏幕在一段时间后自动锁定时,我得到“无法销毁活动(NullPointer)”错误。
我一直在阅读类似的帖子,但我无法让它发挥作用。
以下是用户按下或菜单按钮时调用的方法:
private void showPauseDialog()
{
this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Handler mHandler = new Handler();
MadhonActivity.this.mMusic.pause();
AlertDialog.Builder builder;
//AlertDialog alertDialog;
LayoutInflater inflater = (LayoutInflater) MadhonActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pause,(ViewGroup) getCurrentFocus());//findViewById(R.id.layout_root));
//TextView text = (TextView) layout.findViewById(R.id.stcomplete_score);
TextView text_0 = (TextView) layout.findViewById(R.id.pause_tv);
//text.setText("200");
Typeface font = Typeface.createFromAsset(getAssets(), "font/mvb2.ttf");
//text.setTypeface(font);
text_0.setTypeface(font);
ImageButton btnext = (ImageButton)layout.findViewById(R.id.pause__btnext);
builder = new AlertDialog.Builder(MadhonActivity.this);
builder.setView(layout);
final AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(true);
btnext.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
MadhonActivity.this.mMusic.play();
}});
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
});
}
这是我的onDestroy方法:
protected void onDestroy()
{
madhon_ko.stop(); //sound
mMusic.stop(); //sound
super.onDestroy();
}
任何帮助?
答案 0 :(得分:0)
我认为在onClickListener()方法中,您必须调用要关闭的活动的finish()方法。如需进一步帮助,您可以问我。