Communication between activities in Android-Broadcast Mechanism

Source: Internet
Author: User

I searched android from the Internet.
Broadcast Mechanism, used to implement communication between different activities, or message listening, mainly to implement an activity

The response of another activity in a certain state is as follows:

 

Broadcasttest
Mybroadcastreceiver;

....

// Register the message

Mybroadcastreceiver =
New broadcasttest ();

Intentfilter filter =
New intentfilter ();

Filter. addaction ("namefound ");

Registerreceiver (mybroadcastreceiver, filter );

// Internal class, after receiving the message implementation

Publicclass broadcasttest
Extends broadcastreceiver {

@ Override

Publicvoid onreceive (context arg0, intent arg1 ){

//
Todo auto-generated method stub

Getdata ();

}}

------------------------------------------------------------------------------

// Message broadcast


Intent intent = new intent ("namefound ");

Sendbroadcast (intent );

 

Note:

1. Filter. addaction ("namefound"); and intent =
New intent ("namefound ");
The parameters are consistent;

2. A message broadcast can be sent anywhere. However, if the received message is not registered, it cannot be received.

3. This is the simplest way to use, complex and not tested.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.