Android applications generally consist of one or more components, including Activity, Service, BroardcastReceiver, and ContentProvider.
Activity is a component in the Android application that is responsible for interacting with users. It provides users with Visualized User Interfaces. If an application requires multiple user interfaces, this application requires multiple activities, multiple activities form the Activity stack. The Activity of the current Activity is located at the top of the stack. The Activity component must inherit the Activity base class.
The Service is in parallel with the Activity, and is also a separate Android component. The difference between the two is that the Service is usually run in the background and does not need to interact with users or have no graphical user interface. The Service component has its own independent life cycle. Generally, it provides background services for other components or monitors the running status of other components. The Service must inherit the basic Service class.
BroardcastReceiver is an important component in Android applications. From the code perspective, BroardcastReceiver is very similar to the listener in event programming, but its listening object is other components in Android applications. It is relatively simple to implement BroardcastReceiver. You only need to inherit the BroardcastReceiver base class and override the onReceiver method. When other components send broadcast messages through the sendBroardcast, sendStickyBroardcast, or sendOrderedBroardcast method, if the BroardcastReceiver is also interested in the message, the BroardcastReceiver onReceive method will be triggered.
ContentProvider
For Android applications, they must be relatively independent and run in their own Dalvik Virtual Machine instances. If different applications need to implement real-time data exchange. The Android system provides a standard for cross-application data exchange: ContentProvider. When you implement your own ContentProvider, You need to implement the following Abstract METHODS:
Insert: Insert data to ContentProvider
Delete: Delete the specified data in ContentProvider.
Update: updates the specified data in ContentProvider.
Query: Query data from ContentProvider
ContentResolver is usually used in combination with ContentProvider. One application uses ContentProvider to expose its own data, and the other application uses ContentResolver to access data.
Intent and IntentFilter
Strictly speaking, Intent is not an Android component, but it plays a very important role. It is the carrier for communication between different Android components. Intent can start another Activity in the application, start a Service component, and send a broadcast to trigger BroardcastReceiver in the system. That is to say, the communication between the three components Activity, Service, and BroardcastReceiver uses Intent as the carrier, but the mechanism policies of different components using Intent are slightly different.