Android's basic worldview-system introduction, Component logic, and more

Source: Internet
Author: User
Tags intl

Preface

As an Android Developer with more than half a year of Android developing tossing experience (why not say "development experience"?) Because I think about it, I have not yet independently made a perfect and useful application. To systematically learn the basic development skills of the Android platform, the first step is to understand and familiarize yourself with Android's basic worldview , which should be necessary. In the past, this knowledge system is not systematic, more fragmented and scattered, so take this article a little finishing.

I think that before entering any more complex knowledge and skill system, we need to warm up with the basic world view first. For high school physics, the basic World Outlook is formed by the knowledge of mathematics physics in junior middle schools; for chinses rhymed poetry writing, the Rhetoric of ping Shui rhyme and antithesis is the basic world view; For Android, the basic world view includes an introduction to Android, the meaning of four components, and some other basic development logic.

Android System history and current situation

Android (Android system), an open-source mobile operating system based on the Linux kernel , is continuously led and developed by Google's Open handset Alliance (OHA, open Handheld Alliance), Primarily designed for touch-screen mobile devices such as smartphones and tablets. Android 1.0 beta came out on November 5, 2007, and the world's first device to really use the Android operating system was the HTC Dream, released on October 22, 2008. The Android system uses the Linux macro kernel, the core language of the system is C and C + +, the main programming development language is java. as of early 2016, the latest version of Android is Android 6.0 "Marshmallow" (cotton candy).

system and System architecture

The Android system is executed on top of Linux kernel, but not gnu/linux. In fact, most Android does not support some of the features of Gnu/linux. In addition to the core of Linux-based, it is the mediation layer, the database element, and the API and application framework written in C/s + +. Android's system architecture is as shown--

It can be seen that the system architecture is broadly divided into four layers: Linux kernel layer, core library layer (and running environment), application framework layer and application layer.

The Linux kernel layer is relatively low-level and is often hidden from the developer.

Android runtime with libraries layer :
Android applications are usually written on a Java basis, and when the program is run, the code of the application is instantly converted to Dalvik Dex-code (Dalvik executable), and then the Android operating system uses the instant-compiled Dalvik the virtual machine to run it. That is, theandroid application is running inside the Dalvik virtual machine , and each application should have a separate Dalvik virtual machine instance (which also guarantees that if an Android application process aborts unexpectedly, will not affect the normal operation of other application processes. )。 Dalvik Virtual machine looks like a JVM at some point (at least I feel), but in fact there's a big difference. The JVM is a stack machine (based on stack), but the Dalvik VM is a register-schema machine. The JVM executes the class format file, while the Dalvik VM executes the DEX format file. the Dalvik VM performs stack management, thread management, security exception management, garbage collection and other important functions by executing DEX code files, which are similar to the JVM.
The Android system also supports the various components we use, including opengl,sqlite,webkit, such as a bunch of magical engines and libraries, through the application framework provided to the developer through the C/s libraries, which is the libraries layer .

Application Framework (Application framework) layer: The significance of the application framework layer is that Android provides developers with a framework development platform that allows developers to extend the framework to develop a wide variety of app applications based on framework principles and logic. Development is also through this layer and the bottom of the interaction, and build a higher level of application layer. This layer includes a variety of system APIs, as well as the use of techniques such as JNI. The application framework includes important components such as activity Manager,window manager,content Provider,view system, which can be understood as a toolkit for developers.

Application Layer : This layer is the most image, and the user level of direct contact, including telephone, SMS, mail and a variety of practical apps, games and so on.

Other features
    • After development, theAndroid SDK tool compiles the code along with all data and resource files into an apk: anAndroid package, an archive file in the. apk format. An APK file contains all the contents of the Android app.
    • By default, each app runs within its own Linux process. Android starts the process when it needs to execute any application components, and then shuts down the process when it is no longer needed or when the system must recover memory for other apps.
    • By default, each app has access only to the components that it needs to perform its work, not to other components. In such a secure environment, apps cannot access parts of the system that they do not have access to, but can still share data and access system services in specific ways with other apps.
    • Apps can request access to device data, such as users ' contacts, text messages, Removable storage devices [SD cards], cameras, Bluetooth, and so on. All app permissions must be granted by the user at installation time. This is the "required permissions" information that will be listed at the time of installation.
Android Four Components Activities

activities are generally a separate screen for the user interface. For example, an e-mail app might have an activity that shows a new mailing list, an activity for composing a new message, and an activity to read the specific content of the message. Multiple activities in an application form an organic whole in a collaborative and aggregated way that improves the user experience, but each activity is independent of other activities. Logically, some other app will be able to start an activity in the email app, like when the camera app starts composing a new message after taking a photo.

An application is usually made up of multiple Activity that is loosely linked to each other. It is generally specified that an activity in the app is a "primary" activity, that is, the activity that is presented to the user when the app is first launched. The activity communicates through the intent component. At development time, each activity must be declared in the Androidmanifest.xml configuration file (that is, the manifest file), or the activity will not be recognized or executed.

About activity life cycle : Activity basically exists in three states, continues (running), paused, and stopped. The seven methods and life cycle details of the activity can be seen:

Basic methods of activity:

 Public  class exampleactivity extends Activity {    @Override     Public void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);//The activity is being created.}@Override    protected void OnStart() {Super. OnStart ();//The activity is on to become visible.}@Override    protected void Onresume() {Super. Onresume ();//The activity has become visible (it's now "resumed").}@Override    protected void OnPause() {Super. OnPause ();//Another activity is a taking focus (this activity is on to being "paused").}@Override    protected void OnStop() {Super. OnStop ();//The activity is no longer visible (it's now "stopped")}@Override    protected void OnDestroy() {Super. OnDestroy ();//The activity is on to being destroyed.}}

These methods collectively define the entire life cycle of the activity--you can monitor three nested loops in the activity lifecycle by implementing these methods:

    • The entire life cycle of the Activity occurs between the OnCreate () call and the OnDestroy () call.
    • The visible life cycle of the Activity occurs between the OnStart () call and the OnStop () call.
    • The Activity's foreground life cycle occurs between the Onresume () call and the OnPause () call.
Services

A service is a component that runs in the background to perform long-running operations or to execute a job for a remote process. The service does not provide a user interface. The service does not affect the interaction of other activities with the user, such as when a user reads a Web page in a browser, another program's service can play songs in the background. Other components, such as activities, can start a service, let it run, or bind it to interact with it.

There are two types of services, starting and binding:

    • Started: When an application component (such as Activity) starts a service by calling StartService (), the service is in the "Started" state. Once started, the service can run indefinitely in the background, even if the component that started the service has been destroyed or not affected. It is visible that when a service is a started state, its life cycle is independent of the component that initiated it.
    • Bound: When an application component binds to a service by calling Bindservice (), the service is in a "bound" state. The binding service provides a client-server interface that the binding service will run only if it is bound to another application component. the caller (such as an activity) binds to the service, and once the caller exits, the service terminates. Multiple components can be bound to the service at the same time, but after all unbinding, the service is destroyed.

It is important to note that services can also exist in two ways-the key to the problem is the implementation of the callback method. In addition, as with activity, all services need to be declared in the program manifest.

The life cycle of a service is simple:

Content Providers

content providers manage a set of app data that can be shared, also called a content provider. Other apps can query through the content provider or even modify the data if the content provider allows it. For example, an Android system can provide content providers that manage user contact information. In addition, the content provider is useful for reading and writing private data that is not shared. It has the advantage of unifying the way data is accessed. The main use of Content provider is to use the Contentresolver object as a client to communicate with the provider.

A content Uri is a URI that is used to identify data in a provider. The content URI includes the entire provider's symbolic name (its permissions) and a name (path) that points to the table. The URI here is prefixed with content://, which indicates that the data is managed by ContentProvider.

Broadcast Receivers

A broadcast receiver is a component that responds to system-wide broadcast notifications. Many broadcasts are initiated by the system-such as low battery power. Apps can also initiate broadcasts, such as notifying other apps that some data has been downloaded to the device and available for use. An app can use it to filter external events and receive and respond to external event notifications that are of interest, such as when a phone calls in, or when a WiFi network is available.

Broadcast receivers do not display the user interface , but they can create status bar notifications that alert users when a broadcast event occurs. There are two methods for registering the broadcast receiver, namely the dynamic registration of the program and the static registration in the Androidmanifest manifest file. This component can be seen as a "bridge" for inter-program communication.

additional information about the component

According to official documents boasting, the unique thing about Android is that any application can launch components from other applications. For example, if you want a user to take a photo using the device's camera, there's a good chance another app can do it, and the app can take advantage of another app instead of developing an activity to take photos from the line.

When a component is started by the system, the process of the app is started (if it is not already running) and the classes required by the component are instantiated. Three-activity, service, and broadcast receivers in four component types-start with an asynchronous message named Intent . Intent binds the components to each other at run time (you can treat intent as the messenger of the request operation).

manifest file

Before the Android system launches the application component, the system must confirm that the component exists by reading the app's androidmanifest.xml file (the "manifest" file). The app must declare all its components in this file, which must be in the root directory of the app project directory. Activities, services, and content providers that are not declared in the Androidmanifest file are not visible to the system and are therefore not available.

Of course, the manifest file has other important functions, such as:

    • Determine any user rights that your app requires, such as Internet access or read access to a user's contacts.
    • According to the API used by the app, declare the minimum API level required for the application (e.g. 6.0 system API levels is 23, 4.3 is 18).
    • Declare the hardware and software features that your app uses or needs, such as cameras, Bluetooth services, or multi-touch screens.
Application Resources

Android apps are obviously not just code-it also requires resources that are separate from source code, like, audio files, and any content that is relevant to the application's specific rendering. for each resource, the SDK build tool defines a unique integer IDthat can be used to reference resources in the application code or other resources defined in the XML. Various resources should be placed in the project res/directory of the specific sub-directory, the common directory has drawable, layout, mipmap, values and so on.

how to get started with Android development

To get started with Android development, I personally think it is necessary to be prepared as follows:

    1. Mastering the Java language requires at least no syntax errors in writing code.
    2. Get an initial look at Android's worldview, as described above.
    3. Build the development environment, configure the JVM environment (and Java environment such as JDK), Android Studio (Google's official recommended development platform has replaced Eclipse), the Android SDK (for ADB, application debugging and API management, etc.) with Genymotion (the currently popular Android Virtual device plugin tool is better than the AVD that comes with Android studio).
    4. Learn to use Google search and the official Android website effectively.

The above is the simple preparation required to become an Android developer, Android developing itself is a complex system, learning is not a small difficulty, it takes a lot of time and effort, but development itself is a happy and full of accomplishment in any event.

References

Here is a list of resources for this article, as well as more reading material on the subject of this article.

Https://en.wikipedia.org/wiki/Android_ (Operating_system)
http://blog.csdn.net/luoshengyang/article/details/8852432
http://blog.csdn.net/andyxm/article/details/6126907/
Http://developer.android.com/intl/zh-cn/guide/components/fundamentals.html
Http://developer.android.com/intl/zh-cn/ndk/index.html
http://blog.csdn.net/cruise_h/article/details/12610133
Http://developer.android.com/guide/index.html
http://blog.csdn.net/ican87/article/details/21874321

Android's basic worldview-system introduction, Component logic, and more

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.