First, let's talk about the specific practice. The reason is as follows:
After writing the Alter function block, add the following before the alter. show () Statement:
Alert. getWindow (). setType (WindowManager. LayoutParams. TYPE_SYSTEM_ALERT );
Note: alter is an AlertDialog type object.
Then add the permission to AndroidManifest. xml:
<Uses-permission android: name = "android. permission. SYSTEM_ALERT_WINDOW"> </uses-permission>
The following is a simple explanation:
If you only write the Alter code that is often used in the Activity in the Service, an error will occur during running, because the display of Alter needs to be attached to a definite Activity class. The above method is to declare that the prompt box we want to pop up is a system prompt box, that is, a global prompt box, so as long as the phone is in the boot status, no matter what interface it is in, you only need to call alter. show (), a prompt box will pop up.