Android Application Fundamentals-basic knowledge of Android applications

Source: Internet
Author: User
Tags change settings

Android Application Fundamentals-basic knowledge of Android applications
Application Fundamentals-basic Application knowledge

Key classes-Key classes

  1. Activity
  2. Service
  3. BroadcastReceiver
  4. ContentProvider
  5. IntentIn this document -- In this article
    1. Application Components -- Application Components
      1. Activating components: intents -- activate component: Intent
      2. Shutting down components -- disable components
      3. The manifest file -- inventory file
      4. Intent filters -- Intent matters
      5. Activities and Tasks -- Activities and Tasks
        1. Affinities and new tasks -- affinity and new tasks
        2. Launch modes -- load a style
        3. Clearing the stack -- clear the stack
        4. Starting tasks -- start the task
        5. Processes and Threads -- Processes and Threads
          1. Processes -- Process
          2. Threads -- thread
          3. Remote procedure CILS -- Remote procedure Call
          4. Thread-safe methods -- Method of Thread Insurance Technology
          5. Component Lifecycles -- Component lifecycle
            1. Activity lifecycle -- Activity lifecycle
            2. Service lifecycle -- Service lifecycle
            3. Broadcast receiver lifecycle -- Broadcast receiver lifecycle
            4. Processes and lifecycles -- Process and lifecycle

              Android applications are written in the Java programming language. The compiled Java code-along with any data and resource files required by the application-is bundled byaaptTool intoAndroid package, An archive file marked by.apkSuffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single.apkFile is considered to be oneApplication.
              Android applications are written in Java programming language. Compiled Java code -- used together with the data and resource files used by all applicationsaaptTool is packaged into an Android package with the suffix.apk. This file is a media for publishing apps and installing apps on mobile devices; it is a file that users download to their devices. All the code in a .apk file is considered as an application.

              In every ways, each Android application lives in its own world:
              In many aspects, every Android program runs in its own space:

              • By default, every application runs in its own Linux process. android starts the process when any of the application's code needs to be executed, and shuts down the process when it's no longer needed and system resources are required by other applications. by default, each program runs in its own Linux Process. Android starts a process when a code segment in the application needs to be executed. It is no longer used or shut down when system resources are requested by other applications.
              • Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications. each process has its own Java Virtual Machine (VM). The code running of an application is separated from the code of other programs and is not affected by the code of any other program.
              • 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 Components

                A 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 ActivityBase 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 isIntentObject 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 objectContext.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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.