Skip to content Skip to sidebar Skip to footer

Unable To Dismiss AlertDialog

Hi need to show a AlertDialog from a Service. This is my implementation. I added the permission: But

Solution 1:

This is working for my service

              try{
                    new Thread() {
                        @Override
                        public void run() {
                            Looper.prepare();
                            AlertDialog.Builder builder = new AlertDialog.Builder(
                                    getApplicationContext());

                            builder.setMessage("My messgae").setTitle("My Title");
                            builder.setPositiveButton("Ok",
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface arg,
                                                            int which) {dialog.cancel();
                                        }
                                    });

                            dialog= builder.create();
                            dialog.getWindow().setType(
                                    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                            dialog.show();
                            Looper.loop();
                        }
                    }.start();
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }

Solution 2:

try this:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("")
            .setCancelable(false)
            .setPositiveButton("Yes",null);
    AlertDialog alert = builder.create();
    alert.show();   
}

Post a Comment for "Unable To Dismiss AlertDialog"