Particular points to note are as follows:
- 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