【问题标题】:Unable to destroy activity when alertdialog is opened and screen locks打开警报对话框并锁定屏幕时无法销毁活动
【发布时间】:2012-06-20 05:38:30
【问题描述】:

当我的游戏显示暂停警报对话框并在一段时间后自动锁定屏幕时,我收到“无法销毁 Activity (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();

 }

有什么帮助吗?

【问题讨论】:

    标签: android android-activity android-alertdialog andengine lockscreen


    【解决方案1】:

    我认为在onClickListener() 方法中,您必须调用要关闭的活动的finish() 方法。

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多