On the architecture of Android system and the directory Structure of program project _android

Source: Internet
Author: User
Tags vector font

Android Frame Structure
directly above:

From the above, we can see that the Android system architecture consists of 5 parts,

are: Linux Kernel (Linux kernel), Android Runtime (Runtime Environment), libraries (class library), application framework (application framework), applications (application).

1.1, Linux Kernel
Android provides core system services based on Linux 2.6, such as security, memory management, process management, network stacks, and drive models. Linux kernel also serves as the abstraction layer between hardware and software, which hides specific hardware details and provides a unified service for the upper level.

If you have studied computer networks know Osi/rm, you will know that the benefits of layering is to use the services provided by the lower level to provide a unified service for the upper tier, shielding the difference between the layer and below, when this layer and the following layer has changed will not affect the upper level. In other words, each layer to provide fixed sap (Service Access Point), professional points can be said to be high cohesion, low coupling.

If you're just doing application development, you don't need to get a deeper understanding of the Linux kernel layer.

1.2, Android Runtime
Android contains a collection of core libraries that provide most of the functionality available in the Java programming language Core class library. Each Android application is an instance of the Dalvik virtual machine running in their own process. The Dalvik virtual machine is designed to run multiple virtual machines efficiently in one device. The Dalvik virtual machine executable file format is. dex,dex format is a compressed format designed for Dalvik, which is suitable for systems with limited memory and processor speed.

Most virtual machines, including JVMs, are based on stacks, while the Dalvik virtual machines are based on registers. DX is a set of tools that converts Java. class to A. dex format. A dex file usually has multiple. class. Since Dex had to be optimized, it would increase the file size by 1-4 times to Odex end. (Note that Android is optimized to make it more adaptable to small memory environments in the process of converting to. dex files.)

Dalvik virtual machines rely on the Linux kernel to provide basic functionality, such as threading and underlying memory management.

1.3, libraries
Android contains a collection of C/COM + + libraries for use by various components of the Android system. These features are exposed to developers through the Android application framework (application framework). Some of the core libraries are listed below:

(1) System C Library--standard C system library (LIBC) of the BSD derivative, adjusted to embedded Linux devices
(2) Media Library--based on the PacketVideo Opencore. These libraries support the playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, PNG
(3) interface management--management access to display subsystem and seamless combination of multiple applications of the two-and three-dimensional graphics layer
(4) libwebcore--new Web browser engine, driving Android browser and embedded Web view
(5) sgl--basic 2D graphics engine
(6) 3D Library--based on the implementation of OpenGL ES 1.0 APIs. Library uses hardware 3D to accelerate or contain highly optimized 3D software gratings
(7) freetype--bitmap and vector font rendering
sqlite--a powerful and lightweight relational database engine that all applications can use

1.4. Application Framework
by providing an open development platform, Android enables developers to develop extremely rich and innovative applications. Developers are free to take advantage of device hardware advantages, access to location information, running background services, setting alarms, adding notifications to the status bar, and much more.

Developers can fully use the framework APIs used by core applications. The architecture of an application is designed to simplify the reuse of components, and any application can publish his functionality and any other application may use them (subject to the security restrictions that the framework enforces). This mechanism allows the user to replace the component.

All applications are actually a set of services and systems, including:

(1) View--a rich, extensible collection of views that can be used to build an application. Includes lists, grids, text boxes, buttons, and even embedded web browsers
(2) Content Providers--enables applications to access data from other applications, such as newsletters, or share their own data
(3) Resource Manager (Resource Manager)-provides access to non-code resources such as localized strings, graphics, and layout files
(4) Notification Manager (Notification Manager)--Enables all applications to display a custom warning in the status bar
(5) Activity Manager-Managing application lifecycle, providing common navigation fallback functionality

1.5, applications
Android assembles a collection of core applications, including e-mail clients, SMS programs, calendars, maps, browsers, contacts, and other settings. All applications are written in the Java programming language. More rich applications to us to develop!

Directory structure for general projects and brief descriptions
Our example here is as shown in the figure:

src folder, as the name suggests, is the place to store Java source code.

For example, our code is as follows

Package cn.com.android.phone; 
Import android.app.Activity; 
Import android.content.Intent; 
Import Android.net.Uri; 
Import Android.os.Bundle; 
Import Android.view.View; 
Import Android.view.View.OnClickListener; 
Import Android.widget.Button; 
 
Import Android.widget.EditText; 
  public class Phonecaller extends activity {private EditText edittext; 
    @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
     
     Setcontentview (R.layout.main); 
     
    EditText = (edittext) Findviewbyid (R.id.edittext); 
    Button button = (button) Findviewbyid (R.id.mybutton); Button.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {String number = EditText. 
        GetText (). toString (); 
        Statement of intent to call Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" +number)); 
      Pass the intention to the operating system PhoneCaller.this.startActivity (intent); 
   
  } 
  
    }); 

 } 
}

Our class inherits the class of activity. Generally we will implement the OnCreate method and the OnPause method

1.onCreate method

This method is primarily used to initialize our activity. When a user interacts with us through a request, we deal with it through the activity. The activity, functionally speaking, is more like action in struts. is an interface between system and user interaction.

2.onPause method

The method that is executed before your activity is destroyed is typically used to instantiate the data. (activity is destroyed for many reasons, such as artificial, or low system memory, etc.).

3.gen folder

Gen folder, mainly contains a R.java file, this file is automatically maintained by the system, do not allow artificial modification, otherwise there will be many make you depressed error.

R.java is an index file for Android resources that defines a large number of static internal classes and static constants, and the names of static classes correspond to folder one by one under the Res folder. As shown in figure


Since all are index files, then the role of the file and the index in the database must be similar. It can help us to quickly locate the file, in addition, the compiler will also check whether the resources defined in the R.java are used, if not used, then hit the installation package, will automatically filter out those unused resources, which can greatly save space.

(in the emphasis again, it's okay don't blindly change R.java file)

4.Android 2.2 Folder

Nothing to say, a base jar package.

5.asset folder

The folder usually holds some resource files, such as mp3/video files, and so on.

This file is called the native folder, meaning that the files stored here will be packaged as they are packaged, without compression, and so on. This is not the same as the files under the Res folder, and the resource files under RES are compressed. The main purpose, in fact, is to save space.

6.res folder

There are three main subfolders, drawable_?dpi, layout, values
DRAWABLE_?DPI: Many people wonder why there are three subfolders in this folder, drawable_hdpi High resolution, drawable_ldpi low resolution, DRAWABLE_MDPI general resolution, In fact, this is related to the file optimization compression we mentioned in asset, and Android uses a different compression optimization algorithm for files under three folders. This ensures that we have higher resolution requirements for some pictures and that these resources do not occupy too much space.

Layout store layout files. Includes the master layout file and general component layout files.

Values can be stored in a lot of. xml files, such as Arrays.xml, Colors.xml, Dimens.xml, Styles.xml, and of course the names of these XML files are randomly obtained.
7.androidmanifest.xml
There's nothing to say, Android projects all with a list of program components and something to interact with.
8.default.properties

Records the environment information that the project is running, such as the version requirements for Android.
The total configuration file for the project, documenting the various components used in the application. This file lists the features provided by the application, in which you can specify the services that the application uses (such as telephony, Internet services, SMS services, GPS services, and so on). Also, when you add a new activity, you need to configure it in this file, and you will only be able to invoke this activity once you have configured it. Androidmanifest.xml will include the following settings: Application permissions, activities, intent filters, and so on.

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.