“android.view.WindowManager$BadTokenException: Unable to add window” on buider.show()

前端 未结 10 890
忘掉有多难
忘掉有多难 2020-11-22 10:43

From my main activity, I need to call an inner class and in a method within the class, I need to show AlertDialog. After dismissing it, when the OK

10条回答
  •  没有蜡笔的小新
    2020-11-22 11:09

    Try this :

        public class  extends Activity{
    
        private AlertDialog.Builder builder;
    
        public void onCreate(Bundle savedInstanceState) {
                        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        super.onCreate(savedInstanceState);
    
                    setContentView(R.layout.); 
    
                    builder = new AlertDialog.Builder(.this);
                    builder.setCancelable(true);
                    builder.setMessage();
                    builder.setInverseBackgroundForced(true);
    
            //call the  class to execute
    }
    
        private class  extends AsyncTask{
    
        protected String doInBackground(String... params) {
    
        }
        protected void onPostExecute(String result){
            if(page.contains("error")) //when not subscribed
            {   
               if(builder!=null){
                    builder.setNeutralButton("Ok",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton){
                        dialog.dismiss();
                            if(!)
                            {
                            try
                            {
                            String pl = ""; 
    
                            mHelper.(.this, SKU, RC_REQUEST, 
                            , pl);
                            }
    
                            catch(Exception e)
                            {
                            e.printStackTrace();
                            }
                        }  
                    }
                });
    
                builder.show();
            }
        }
    
    }
    }
    

提交回复
热议问题