Android in Service,broadcast Onreceiver () Pop-Up Dialog dialog box

Source: Internet
Author: User
Tags what interface

After writing the ALTER function block, add it before the Alter.show () statement:

Alert.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

NOTE: Alter is an Alertdialog type Object

Then add the permissions in the Androidmanifest.xml:

<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW" ></uses-permission>


The following is a simple explanation:

If you write only the code of the create alter that is used in the activity in the service, the runtime is wrong, because the alter display needs to be dependent on a certain activity class. And the above practice is to declare that we want to pop up this prompt box is a system prompt box, that is, the global nature of the prompt box, so as long as the phone is turned on, no matter what interface it is now, as long as the call Alter.show (), will pop up the prompt box.

The demo is as follows:

Alertdialog.builder builder = new alertdialog.builder (this);  builder.setmessage ("is  you sure you want to exit? ")         .setcancelable (False)          .setpositivebutton ("Yes",  new dialoginterface.onclicklistener ()  {             public void onclick (DialogInterface  Dialog, int id)  {                  myactivity.this.finish ();             }        })          .setnegativebutton ("No",  new dialoginterface.onclicklistener ()  {             public void onclick (DIaloginterface dialog, int id)  {                  dialog.cancel ();             }        });         alertdialog alert = builder.create ();    alert.getwindow ( ). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);   alert.show ();


Android UI Learning-dialog box (Alertdialog & ProgressDialog)
http://android.blog.51cto.com/268543/333769


Android in Service,broadcast Onreceiver () Pop-Up Dialog dialog box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.