android broadcast

android broadcast:

Normal broadcast:

1. Configure the broadcast receiver in AndroidManifest.xml:

       <receiver android:name="com.example.toast.MyBroadReceiver" >
            <intent-filter>
                <action android:name="MyBroad" />
            </intent-filter>
        </receiver>

2. Need to inherit a BroadcastReceiver object

3. Pass the message through the intent method

4. Finally, you need to call the context's sendBroadcast(intent) method

Ordered broadcasting: Same as regular broadcasting, but ordered broadcasting has priority, requires multiple receivers, and the delivered message can be terminated anywhere, and messages can be added anywhere, but the propagated message needs to be packaged ( ) in the form of transfer,

for example:

        Bundle bundle=new Bundle();
        bundle.putString("mes2", "01已收到");
        setResultExtras(bundle);

And the receiver needs to get the message in the package and needs to use Bundle bundle = getResultExtras(true); to receive.

System broadcast:

Notification:

1. Mainly involved in 3 categories:

Notification.builder is used for dynamic Notification property set to set

Notification Manager is mainly the display and cancellation of notifications

Notification setsthe relevant properties of Notification

2. Need to send Notification

1). Call the getSystemService(NOTIFICATION_SERVICE) method to obtain the Notification Manager service of the system

2). Create Notification object

3). Set the Notification property

4). Send Notification through Notification Manager

5). Send notify to cancel cancel

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325558713&siteId=291194637