In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article editor for everyone to introduce in detail "what are the core components of Android", the content is detailed, the steps are clear, the details are handled properly, I hope this article "what are the core components of Android" can help you solve your doubts, following the editor's ideas slowly in depth, let's learn new knowledge.
Activity
Activity is one of the most basic core components of Android applications. Activity is used to deal with UI-related business, such as loading interfaces and listening for user action events. Is the window where the user interacts with the application.
In Android applications, an Activity usually corresponds to a separate view. An Android application is made up of one or more Activity, which are equivalent to web pages in a Web application, are used to display information and can jump to each other. Unlike a web jump, a jump between Activity can have a return value.
Activity, which is maintained by the Android system, has its own life cycle, namely "generate, run, destroy", but many methods are called in the process, including seven life cycle methods, creating onCreate (), activating onStart (), restoring onResume (), pausing onPause (), stopping onStop (), destroying onDestroy (), and restarting onRestart (), and so on. The detailed process is shown in the following figure:
To create an Activity, you need to inherit from the class android.app.Activity, override onCreate (), and call setContentView (parameter) in onCreate () to load the layout, which is the layout file. For configuration, you need to register Actvitiy under the Application node of the manifest file. If you want to start the Activity first, add an intent-filter node with a category node and a value of LAUNCHER. The configuration of the manifest file is as follows.
Service
Service is a program similar to Activity but without views. It has no user interface and can run in the background for a long time, which is equivalent to a service in the operating system.
Another function of Service is to raise the priority of the process (each application is a process). The priority of the process means that in the Android system, the running application will be given a priority. When the memory space is insufficient, the system will clean up the memory space occupied by part of the process according to the priority of the process to get enough memory space for the newly enabled application to run.
There are two definitions of Service in Android, local Service and remote Service. The local Service is a component that can only be accessed by the application that hosts the Service, while the remote Service is the Service that other applications running on the device can access remotely.
You can start a Service through Context.startService (Intent service), where the intent definition method is similar to the jump Activity, only by replacing the Actvity class with the Service class. Its life cycle is onCreate () on startup-> onStartCommand ()-> onDestroy () on destruction, and repeated calls to startService () will only cause Service to execute onStartCommand () repeatedly.
Through Context. BindService () can bind a Service. Call the bindService () method to bind Activity to Service, and call unbindService () to unbind it. You must unbind the Activity from the Service before it can be destroyed. The life cycle is onCreate ()-> when the first binding time is executed-onBind ()-> when the first binding time is executed-onDestroy ()-> when the binding is unbound.
The following figure shows the Service lifecycle description of two states:
BroadcastReceiver
BroadcastReceiver means "broadcast receiver" and, as its name implies, it is used to receive and respond to broadcasts from the system and other applications. So ContentProvider can share the application's own data (to other applications), so that other applications can add, delete, modify and check their own data.
In the Android system, when a specific event occurs, the corresponding broadcast will be generated. Broadcasting is reflected in every aspect. For example, when the boot process is completed, the system will generate a broadcast, and when it is received, the system will be able to boot up and start the service; when the network state changes, the system will generate a broadcast, and when it receives this broadcast, it will be able to prompt and save data in time. When the battery charge changes, the system will generate a broadcast, which can inform the user to save the progress in time when the battery is low.
There are two ways to register BroadcastReceiver:
In AndroidManifest. Static registration in xml
Use Context.registerReceiver () for dynamic registration in the code at run time.
As long as BroadcastReceiver is registered, the system automatically starts the application to handle the event, even if the corresponding event broadcast emergency application is not started. In addition, users can broadcast their Intent objects to other applications through Context.sendBroadcast ().
ContentProvider
A broadcast receiver, as its name implies, is a system component used to receive broadcasts sent by an application. Files, databases and other data are private within the Android system and are only allowed to be used directly by specific applications. Between the two programs, the exchange or sharing of data is realized by ContentProvider. Broadcasting is an one-to-many mode of communication, that is, there is one sender and several receivers.
The ContentProvider class implements the interface of a set of standard methods, which allows other applications to save or read various data types provided by ContentProvider.
Intent
Intent is not one of the four core components of Android applications, but its importance is irreplaceable. The three core components in the core components of Android applications-Activity, Service, BroadcastReceiver. Activation is initiated through the message mechanism, and the message used is Intent. Intent is an abstract description of the upcoming operation, which undertakes the communication function between the three core components of the Android application, so it is very important.
After reading this, the article "what are the core components of Android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.