Notebook Android four major pieces

1. Activity

1. The user visual interface creates a window for the user to complete the operation instruction. After creating the Activity, you need to call the setContentView() method to complete the display of the interface; in order to complete the user interaction entry. Almost all apps rely on Activity, so Activity is the most used component in development.
2. An activity is usually a separate window.
3. Activities communicate through Intent.
4. Declare in the AndroidMainfest.xml configuration file, otherwise the system will neither recognize nor execute the program. Android studio will automatically generate it, but eclipse needs to be added manually.
5. Life cycle: Activity Stack activity stack, activities are carried out in the form of a stack
a, running: located on the top of the stack, visible, and can interact with users
b, paused: loses focus, cannot interact, but is visible. When a new non-full screen or transparent activity is pressed on it, it is suspended, the data is saved, and it is destroyed when the system memory is extremely low c. Stop: completely covered by another
activity, or click home to enter the background. Although the data is saved, when the system uses the content in other places, it will automatically destroy the activity.
d. Destruction: When we click Back or the system does not have enough memory, the activity will be automatically destroyed from the stack and recycled by the system.
android activity

2. Service

1. It is usually used as the logic for background processing. Like Activity, it has its own life cycle, and related information needs to be configured in AndroidMainfest.xml. Service is Android's solution to implement the background of the program, suitable for those tasks that do not need to interact with the user but also require long-running tasks. There are start Service and bind Service.
2. There are two Service states:
a. Started: When the application component calls the startService() method to start the service, the service is in the started state.
b. Bound: When the application component calls the bindService method to bind the server, the service is in the bound state.
3. startService: just start the Service, the component that starts it has nothing to do with the Service, the service will be terminated only if the Service calls stopSelf or other components call StopService.
bindService: This method starts the Service, and other components can obtain the proxy object of the Service and interact with the Service through the callback function, and the two parties are also bound. When it is started and destroyed, the Service will also perform the UNBind operation. When all bindings are found The Service will be destroyed only when UNBind is performed.
android service

3. Broadcast Receiver

1. Broadcasting is a widely used mechanism for transferring information between applications. The broadcast receiver is a type of component that filters and responds to broadcasts sent out. You can use broadcast receivers to respond to external events. Broadcast receivers can be registered in AndroidMainfest.xml, or in runtime code using Context.registReceive() to register. As long as you register, when the event comes, even if the program is not started, the system will start the program when needed. Various applications can also broadcast their own intents to other applications through Context.sendBroadcast.
2. Your application can use it to filter external events, and only receive and respond to external events of interest (such as when a phone call comes in, or when a data network is available). Broadcast receivers have no user interface. However, they can start an activity or serice in response to the information they receive, or use the NotificationManager to notify the user. Notifications can be used in many ways to attract the user's attention, such as flashing the backlight, vibrating, playing a sound, and so on. The general rule is to put a persistent icon on the status bar that the user can open and get messages.
3. There are two ways to register broadcast receivers, namely program dynamic registration (using Context.registerReceive() to register in the runtime code) and static registration in the AndroidManifest file.
4. The characteristic of dynamic registration broadcast receiver is that when the Activity used for registration is closed, the broadcast will be invalid. Static registration does not need to worry about whether the broadcast receiver is turned off, as long as the device is turned on, the broadcast receiver is also turned on. That is to say, even if the app itself is not started, the broadcast subscribed by the app will also work on it when triggered.

4. Context Provider content provider

1. The android platform provides a Content Provider to make the specified data set of an application available to other applications. Other applications can obtain or store data from this content provider through the ContentResolver class.
2. A content provider is only required if data needs to be shared between multiple applications. For example, address book data is used by multiple applications and must be stored in one. 3. ContentProvider realizes data sharing. ContentProvider is used to save and fetch data and make it visible to all applications. This is the only way to share data between different applications, because android does not provide a common storage area that all applications can access.
4. Developers will not directly use the objects of the ContentProvider class. Most of the operations on the ContentProvider are realized through the ContentResolver object.
5. ContentProvider uses URI to uniquely identify its data set. The URI here is prefixed with content://, indicating that the data is managed by ContentProvider.

Guess you like

Origin blog.csdn.net/weixin_44440669/article/details/119238704