You can register a broadcast in either of the following ways:
1. Write a *** broadcastreceiver inherited from the system's broadcastreceiver to implement its
Onreceive method. Then you can register in the mainfest. xml file to accept the broadcast.
2. Define an intentfilter to filter the specified action, and then register it through the registerreceiver of the activity.
However, for the second method of registering broadcast, there is no problem in versions earlier than android4.0. In android4.0, if you have a sub-activity,
And you want to register a broadcast in the sub-acitivity, then you are miserable,ProgramKeep crash and prompt java. Lang. securityexception.
Solution: Because the sub-acit on android4.0 restricts the registration broadcast behavior, but if you need to register the sub-acitvity, you need to use the context of the parent activity,
Use the context of the parent activity to register the broadcast instead of the context of the Child Activity.
Note:
On Android 4.0:
Subactivity cannot register broadcast, create database, and start a new activity.