Detailed explanation of local broadcast usage for Android learning

Local broadcast information can only be transmitted within the application, and the broadcast receiver can only receive broadcast messages within the application.

Mainactivity code

First, get the instance through the getInstance (this) method of localbroadcastmanager (local broadcast management class). When registering broadcast messages, call the registerreceiver (parameter 1, parameter 2) method of localbroadcastmanager instance to register (parameter 1 is the local broadcast receiver, parameter 2 is the filter, and only select to receive specific broadcast messages), Call the sendbroadcast (initial) method of the localbroadcastmanager instance to send a broadcast message.

MyRecevity

activity_ main.xml

AndroidMainfest.aml

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>