Android program component Interaction Analysis

Source: Internet
Author: User

Android applications consist of some basic elements. But how can they interact?

Activity-> activity:

Activities interact with each other through intent. You can directly jump through the class name or perform matching analysis through intent filter, and then find the corresponding activity to switch. This is a loose coupling.

Internal activity:

Within the activity, view, button, and other UI components listen to and process UI events by setting the listener.

Progress-> progress:

You can use the braodcast intent method to interact with the target component, or use a general intent. For example, if the activity calls another activity, you can use startactivity (new intent (XX. This, YYY. Class.

 Any-> broadcastreceiver
The initiator sends a pendingintent, broadcastreceiver onreceive (context, intent) called
Any-> contentprovider
The caller uses the getcontentresolver () method to obtain the contentprovider configured in androidmanifest. xml and then uses the URI method to operate on the target.
Intent intent = getintent ();
If (intent. getdata () = NULL) intent. setdata (content_uri );
Cursor cur = getcontentresolver (). Query (getintent (). getdata (),
Projection, null );

Any-> Service
It can be called by the initiator context. startservice (new intent (context, XXX. Class) or by the service name.

From birth to death:

Select the program file image, start the module to start the process, and send intent to this process. This process matches an activity through the intent filter and runs oncreate of this activity. when the user terminates the program, or the android program manager takes precedence over the process due to memory and other principles, kill the process.

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.