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.