By default, each application is assigned a unique Linux user ID. permissions are set so that the application's files are visible only that user, only to the application itself-although there are ways to export them to other applications as well. by default, each application has a Linux User ID. Because of permission settings, an application file is only visible to the current user (its own)-of course, there is also a mechanism to export them to other applications.
It's possible to arrange for two applications to share the same user ID, in which case they will be able to see each other's files. to conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM.
You can arrange for two applications to use the same user ID so that their files are visible to each other. To save system resources, programs with the same ID can run as a Linux Process and share the same virtual machine.
Application Components -- Application ComponentsA central feature of Android is that one application can make use of elements of other applications (provided those applications permit it ). for example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. your application doesn' t induplicate ate the code of the other application or link to it. rather, it simply starts up that piece of the other application when the need arises.
A central function of Android is that applications can use elements of other applications (when the application that provides the elements is allowed ). For example, if your application wants to display a series of images with the sliding screen function, then an application happens to develop a suitable Sliding Screen module and agree to share it, you can call the slide screen module to process and display these images, instead of developing one by yourself. Your application does not contain or link to the code of another application. However, after a request is sent, your application can simply use some features of other programs.
For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Java objects for that part. therefore, unlike applications on most other systems, Android applications don't have a single entry point for everything in the application (nomain()
Function, for example). Rather, they have essentialComponentsThat the system can instantiate and run as needed. There are four types of components:
In order to achieve this process, the system must be able to start the process of this program when a part of the application is requested. Create an instance for that part of the Java object. Therefore, unlike applications on other operating systems, Android does not have a single application portal (for examplemain()
Function ). However, they contain essential components for creating instances when the system needs them. There are four types of components:
-
Activities-Activity
-
An
ActivityPresents a visual user interface for one focused endeavor the user can undertake. for example, an activity might present a list of menu items users can choose from or it might display photographs along with their captions. A text messaging application might have one activity that shows a list of contacts to send messages to, a second activity to write the message to the chosen contact, and other activities to review old messages or change settings. though they work together to form a cohesive user interface, each activity is independent of the others. each one is implemented as a subclass of
Activity
Base class.
-
Whenever there's a request that shocould be handled by a participant component, Android makes sure that the application process of the component is running, starting it if necessary, and that an appropriate instance of the component is available, creating the instance if necessary.
When there is a request for Special Component Operations, Android will confirm whether the component is running. If not, start it, if you are running, check whether the required class is instantiated. If not, create an instance for the class.
Activating components: intents -- activate the component of another component: Intent
Content providers are activated when they're targeted by a request from a ContentResolver. The other three components-activities, services, and broadcast receivers-are activated by asynchronous messages calledIntents. An intent isIntent
Object that holds the content of the message. for activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. for example, it might convey a request for an activity to present an image to the user or let the user edit some text. for broadcast receivers, the Intent object names the action being announced. for example, it might announce to interested parties that the camera button has been pressed.
After the content provider obtains the point of the ContentResolver request, it will be activated. The other three components-activity, service, and broadcast receiver-depend on the differenceIntents). The intention is to carry the asynchronous message contentIntent
. For activities and services, it is mainly to name the requested action, and then specify the URI for this data operation. For example, it may carry a request that allows an activity to display an image or edit text for the user. For a broadcast receiver, the Intent object is named as the content to be broadcast. For example, it may publish a broadcast where the camera key is pressed to an interest receiver.
There are separate methods for activiating each type of component:
Different methods are required to activate different components:
- An activity is launched (or given something new to do) by passing an Intent object
Context.startActivity()
OrActivity.startActivityForResult()
. The responding activity can look at the initial intent that caused it to be launched by calling itsgetIntent()
Method. Android callthe activity'sonNewIntent()
Method to pass it any subsequent intents. pass the Intent object to Context. startActivity () or Activity. startActivityForResult () to activate (or obtain a new task) an Activity. You can call the getIntent () method to view the initial intent of a response to the activity. Android calls the onNewIntent () method of the activity to pass the subsequent intent.
One activity often starts the next one. If it expects a result back from the activity it's starting, it cballsstartActivityForResult()
InsteadstartActivity()
. For example, if it starts an activity that lets the user pick a photo, it might should CT to be returned the chosen photo. the result is returned in an Intent object that's passed to the calling activity'sonActivityResult()
Method. An activity usually starts another activity. You can callstartActivityForResult()
Method to replacestartActivity()
Method. For example, if an old activity starts a new activity that allows users to take photos, they want to get the picture from the new activity. The running result of the new activity is passed through an Intent object passed to the onActivityResult () method of the old activity.
A service is started (or new instructions are given to an ongoing service) by passing an Intent objectContext.startService()
. Android callthe service'sonStart()
Method and passes it the Intent object.
Similarly, an intent can be passedContext.bindService()
To establish an ongoing connection between the calling component and a target service. The service has es the Intent object inonBind()
Call. (If the service is not already running,bindService()
Can optionally start it .) for example, an activity might establish a connection with the music playback service mentioned earlier so that it can provide the user with the means (a user interface) for controlling the playback. the activity wocould callbindService()
To set up that connection, and then call methods defined by the service to affect the playback. the service is directed to the Context. startService () transmits an Intent object to start (or give a new task) the Android calls the onStart () method of the service and then transmits the Intent object to the service. Similarly, an intent can be passed to Context. bindService () to establish a real-time connection between the call component and the called component. Call the onBind () of the Service to make it accept the Intent object. (If the service is not running, you can choose to usebindService()
To start it .) For example, in the music playing Service mentioned above, the activity will want to establish a connection with this service to provide users with the function of controlling playing (such as a UI interface ). Then the activity will callbindService()
To establish a connection, and then call the method defined in the service to control playback.
A later section, Remote procedure CILS, has more details about binding to a service. The subsequent sections will talk about Remote procedure CILS, which contains more detailed information about binding services.
An application can initiate a broadcast by passing an Intent object to methods likeContext.sendBroadcast()
,Context.sendOrderedBroadcast()
, AndContext.sendStickyBroadcast()
In any of their variations. Android delivers the intent to all interested broadcast receivers by calling theironReceive()
Methods. The program can initialize a broadcast by passing an Intent object to Context. sendBroadcast (), Context. sendOrderedBroadcast (), Context. sendStickyBroadcast (), and their variant methods.
For more on intent messages, see the separate article, Intents and Intent Filters.
Obtain