user1116665
user1116665

Reputation: 85

Unable to destroy activity when alertdialog is opened and screen locks

Im getting the "Unable to destroy Activity (NullPointer)" error when my game is showing a pause alertdialog and screen locks automacatically after a while.

I ve been reading similar post, but I cant get it working.

Here is the method that is called when user press back or menu button:

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




            }
        });
    }

And here my onDestroy method:

protected void onDestroy()
 {  
     madhon_ko.stop(); //sound
     mMusic.stop(); //sound
     super.onDestroy();

 }

Any help?

Upvotes: 0

Views: 307

Answers (1)

Siddharth
Siddharth

Reputation: 4312

I think in onClickListener() method you have to call the finish() method of the activity which you want to close.

Upvotes: 0

Related Questions