2012-06-20 28 views
0

當我的遊戲顯示暫停alertdialog並且屏幕自動鎖定一段時間後,我得到「無法銷燬活動(NullPointer)」錯誤。當alertdialog打開並且屏幕鎖定時無法銷燬活動

我一直在閱讀類似的文章,但我無法得到它的工作。

這裏是調用的方法,當用戶按下後退或菜單按鈕:

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

我認爲,在onClickListener()方法中,您必須調用要關閉的活動的finish()方法。爲了得到更多的幫助,你可以問我。

相關問題