Android Application Basics (Application Fundamentals)

Source: Internet
Author: User
Tags bind thread linux

The android application is written in the Java language, and the AAPT tool packs any data, resource files needed by the application into a APK file, a carrier that installs the application on the phone.

There are many ways in which each Android application exists in a different world:

(1) By default, each application runs in his own Linux process, and Android starts the process when any code in the application needs to be executed, and Android shuts down the process when it is not needed and when system resources are requested by other applications.

(2) Each process has its own virtual machine object (VM), so application code is isolated from other applications.

(3) By default, each application is assigned a unique Linux user ID, all set permissions so that the application's files are visible only to the user or to the application itself.

It is possible to schedule two applications to share a user ID, in which case they can see each other's files, and in order to protect system resources, applications with the same ID can be scheduled to run in the same Linux process, sharing the same VM.

1, Application components (application components)

One of the core features of Android is that an application can use an element of another application (if another application allows it), your application does not need to include another application code that you use and does not require you to connect to the code, but instead, just when the application requires the code, start another application that has the appropriate generation Code (not let another application start all)

To work for this, when any part of an application is needed, the system must be able to start the application process and instantiate this part as a Java object, so unlike most other systems, the Android application does not have a separate program entry (for example: no main () function), instead , the Android app has the necessary components to instantiate and run it when needed, with four components in Android:

(1) Activity

An activity is a user interface that can be used by a visible user, and if there are multiple activities in an application, although each of them is combined to form an application to work together, each of the tasks is independent of each other, each of which is a subclass of an activity.

An application may consist of one or more activity, which shows how many activity is required, depending on the designer of the application, in general, one activity should be marked as the first to be presented to the user when the application is started.

Each activity is given a window to draw by default, and in general, the window fills the entire screen, but he can be smaller than the screen and float on top of another window.

The visible content in one window is made up of some hierarchical view, inherited from the view class, and each view controls a particular rectangular box in a window, and parent view contains the layout of children view and the organization children view. The leaf view (those at the bottom of the inheritance hierarchy) is drawn in the rectangular frame they control and responds directly to the user's actions, so view is where activity and user interaction is, and Android has a lot of good view you can use, including Buttons,text fields,scroll bars,menu items,check boxes, etc.

A view hierarchy is placed in the window of an activity through the Activity.setcontentview () method, and the content view is the topmost view in the view hierarchy.

(2) Services

A service is not a user-visible component that runs in the background for an indeterminate period of time, and each service inherits from the service class.

You can connect (connect) or bind (BIND) to a running service (start it if the service is not already running), and when connected to the service, you can communicate with the service through an interface exposed by the service. For music service, this interface can be used to allow users to pause, rewind, stop, and replay.

Like an activity or other component, the service runs in the main thread of the application process, so he does not block other components or user interfaces, and they often open a separate thread for those time-consuming tasks.

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.