Android Pop-up dialog box in broadcast receiver

Source: Internet
Author: User

Particular points to note are as follows:

    1. Type of Alertdialog to be set

Windowmanager.layoutparams. Type_system_alert

2. Permission to declare the window bullet box

<user-permission android:name= "Android.premission. System_alert_window"/>

3. When you click on the Alertdialog button, if you use intent to make a page jump, FLAG_ACTIVITY_NEW_TASK you need to add a flag to intent

The key code in the receiver is as follows:

1  Public classForceofflinereceiverextendsbroadcastreceiver{2 @Override3      Public voidOnReceive (Finalcontext Context, Intent Intent) {4 5Alertdialog.builder Dialogbuilder =NewAlertdialog.builder (context);6Dialogbuilder.settitle ("Offline notification");7Dialogbuilder.setmessage ("Your account is logged in over elsewhere");8Dialogbuilder.setcancelable (false);9Dialogbuilder.setpositivebutton ("Re-login",Ten                 NewDialoginterface.onclicklistener () { One @Override A                      Public voidOnClick (Dialoginterface Dialog,intwhich) { -Activitycollector.finishall ();//Destroy All Activities -Intent intent1 =NewIntent (context, loginactivity.class); the                         //to start an activity in a broadcast recipient, you need to add the FLAG_ACTIVITY_NEW_TASK flag - intent1.addflags (Intent.  Flag_activity_new_task); - context.startactivity (intent1); -                     } +                 }); -Alertdialog Alertdialog =dialogbuilder.create (); + Alertdialog.getwindow (). SetType (Windowmanager.layoutparams.  Type_system_alert); A alertdialog.show (); at     } -}

Android Pop-up dialog box in broadcast receiver

Related Article

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.