An example of a simplified version of the Android Learning Project (a) _android

Source: Internet
Author: User
Tags java web

This is the opening of the "Android Learning Path" series, which may be a bit disappointing-we don't introduce the implementation of the simplified version of the micro-letter (but not the title party Oh, I'll implement the application step-by-step in the next article). This is primarily to talk to a wide range of friends about a non-Java programmer's understanding of the Android operating system and the directory structure of an Android project to prepare for further learning.

1 origin

The emergence and popularization of smart phones for people's lives, work brought great convenience, we can use the phone anytime, anywhere, shopping, play games, chat, listen to music and so on. Carefully designed, experienced a good mobile client applications, so that users fondle admiringly, people are now increasingly inseparable from the smartphone. This is probably one of the big reasons programmers learn about mobile apps, and that's one of the reasons I'm learning about Android.

Here's why you want to write a series of blog posts about Android development. At present, is to do the development of PC software, the main thing is to use C + + to write image processing and display logic, the software front-end interface with WPF. In the second half of last year, the company encouraged the front end (WPF) to turn back (C + +) and back-end turn front-end, as a self-motivated programmer, of course, to respond to the call of the leadership of ^_^. Then began the WPF study tour, after learning for a while, is a bit of a primer, at least with WPF to do some simple functions. It was also at that time that the blogger began to touch Android, after all, he wanted to be able to upgrade himself after work, so he read some blog posts and related books. On and off for six months, although it feels like WPF in some ways, the understanding of Android is still not profound. So bloggers began to think, how to better understand how to master Android? For a computer (or engineering) professional, the best way to learn is to practice--to choose a project that is not too complex, to make it step by step, and to perfect it a little bit. Based on this, decided to write a series of blogs, record their own learning path and project development path. Micro-credit applications are the most frequently used in our daily apk, the simple version of the micro-letter should not be too complicated, so we are ready to develop a simple version of the micro-letter as the practice of their own Android project trip.

Android in the eyes of 21 programmers

About Android Introduction, development history, current usage and future trends, here do not repeat, these to the vast number of programmers friends must have some understanding. This section focuses on a little superficial understanding of Android from a programmer's point of view, of course, 1000 readers have 1000 hamlet in mind, everyone's understanding of Android will be different, here is only my personal opinion.

Android is an operating system based on the Linux kernel that is designed to be mobile-oriented (and, of course, Android is already on every hardware platform, including Android TV, Android Wear, and so on). Android is essentially the same as a regular Linux desktop PC release, and Android can be seen as a distribution of Linux on the phone, but Google has done a perfect package so that we almost don't feel Linux. The package described here has two layers of meaning:

(1) For ordinary users, Android has become more pro-people, more popular, not as high as Linux, the need for a good computer base of children's shoes to be better used;

(2) For application developers, no need to touch the underlying C code and system library functions, we are faced with some Java-written class library, including the famous Android four components (later we elaborated), a set of more complete UI controls and some auxiliary tool class library.

The Android operating system is layered, and its hierarchy is shown in the following illustration:

It may not be too difficult for a seasoned veteran to understand, but for a little white that soon came into the workplace, it may not be quite clear. But it doesn't matter, for a side dish like ours, there's absolutely no need to figure out all the layers and all the components: like Linux Kernel (kernel) Do you need to learn from the beginning? -The first to go to see these are not on the ^_^!? On the core layer above that layer, what SQLite, Opengl|es, SGL, libc, WebKit and so on are some well-known open source projects, mostly written in C, for the development of the upper application of us, also did not need to learn at the beginning. Finally look at the top layer of--application, home, Contacts, Phone ... These are actually some of the systems built into the application, and we developed the application is no different, so there is no need to spend too much time to understand. For the development of the application of us, to learn the following two layers is good:

First Level: Application framework layer, which is the application framework layer. Most of the components we use to write applications come from here, and the most important of these include:

View system, that is, the views systems, defines a set of UI libraries, including layout classes and control classes, that can be used to define the interface of the application, which is a huge library and a difficult part of our learning about Android development;

Activity Manager, Active Manager, active (activity) is one of the four main components of Android that manages the logic and lifecycle callbacks associated with the user interface display;

Content Provider, which is also one of the four components of Android, is the contents provider. Data is the core of the application, and it is possible to share data across processes/applications using content providers.

Notification Manager, the Notification Manager, is used to display system notifications on the top status bar of the phone, and it is also one of the four components of Android.

Resource Manager, Resource Manager, as the name implies, manages application resources such as icons, background pictures, and constant strings.

There are other components in the diagram, such as Package Manager (Package Manager), Location Manager (position Manager), etc., which is not specifically introduced, the beginner contact is not much.

Second Level: Android runtime layer, which is an Android Run-time layer, is actually a Java Virtual machine--dalvik virtual machine and a core class library. This part of the common Java Virtual machine is the same in terms of use, so this layer although in development will be contacted, but as long as the Java, should understand.

So, so far, we should be aware of the development of Android to learn something, in fact, is in the Learning Application framework layer, the other look on the good, if you want to further in-depth words, wait until the foundation of the study solid again!

3 directory Structure of Android project

The IDE used for Android development includes the Eclipse + Android SDK (Software develement Kit, Software Development Kit), Visual Studio + Xamarin (in C # Language development Android program) and Android studio three options, bloggers are using Android Studio 2.0, download decompression without installation, can be used directly. For the configuration of the JDK for Android Studio, please refer to the relevant blog, and do not repeat it here.

With the IDE, we can easily create an Android project (about project creation, just click Next to Next, and no longer repeat here). Let us now write code to meet a new Android project directory structure, as shown in the following figure:

Directory structure at a glance, we learn about the various levels of directory structure and its role.

3.1 List file

The manifest file is the Androidmanifest.xml file, which is a very important configuration file in the Android project and is written in XML. Children's shoes that have studied the Java Web must know that there are many XML configuration files in the SSH framework. The configuration file in Android is similar to the profile feature in the SSH framework, which provides the necessary data for the framework to run, and the Androidmanifest.xml code for the newly created project is as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
 package=" Com.doll.firstapplicationdemo >

 <application
  android:allowbackup= "true"
  android:icon= "@mipmap/ic_launcher"
  android:label= "@string/app_name"
  android:supportsrtl= "true"
  android:theme= "@style/apptheme" >
  <activity android:name= ". Mainactivity ">
   <intent-filter>
    <action android:name=" Android.intent.action.MAIN "/>

    <category android:name= "Android.intent.category.LAUNCHER"/>
   </intent-filter>
  </ activity>
 </application>

</manifest>

To explain briefly: first manifest the root node, defines the namespace and package name, and then the application node, which represents an application that configures the application's label, name, subject, and so on. The main activity is defined in the application node (a bit like the home page in Web development), and the class name and intent filter are defined in the attribute (this is not detailed here, as described later in detail in the activity). So, when we run the program, the Android framework can help us create the necessary object instances to get our applications running. In fact, bloggers feel that this profile and the Applicationcontext.xml configuration file in the spring framework are similar in functionality. Of course, this configuration file is not immutable, as with the SSH framework configuration file, and as the project continues to evolve, we will write various configuration information to it.

3.2 Code Folders

The code folder includes the Java source Code subfolder and the test Code subfolder, which is expanded as follows:

1. Source code folder

Currently, under the folder, define a activity--mainactivity, which has been mentioned in the list configuration file that was previously described, and the program logic classes that we write later are generally placed in this folder.

2. Test Code folder I (androidtest)

In this folder, place the test code that needs to be written using the Android SDK. Of course, our test code typically uses the Android SDK, so most of the Android test code is in this directory.

3. Testing Code Folder II (test)

Place the test code in this folder that does not need to be written using the Android SDK.

3.3 Resource Folders

The resource is the same as the data we defined before the program is run, and it's an important part of the application, and for this purpose, Android studio uses a single folder to manage the resources used in the application, with a specific directory structure as follows:

An application usually has many types of resources, such as:

Drawable: Can draw resources, such as background picture, background selector, etc.;

Layout:ui layout resources to define the user interface;

Mipmap: Picture resources, from the above figure can be seen, divided into hdpi (high resolution), MDPI (medium resolution), XHDPI/XXHDPI/XXXHDPI (ultra-high resolution ...). Resources, the Android framework automatically chooses the right pictures for your phone's resolution to draw.

Values: There are a few constant resources in this folder, such as color constants, dimension (dimension) constants, string constants, and style constants (which define the display style of the control, like CSS), and so on.

In addition to the resources described above, Android also supports other resources, such as animation resources, color selector resources, menu resources, etc., which will be posting in the future. Further information on how these resources are defined and how they are referenced in other resource files or program code will be posting later.

4 Summary

To conclude, this article describes the reasons for learning about Android, personal understanding of the Android operating system, and the directory structure of the current Android project, where the directory structure is relatively important.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.