Today I saw a very good article about Android, reproduced in my blog park.
Original Address http://www.cnblogs.com/cr330326/p/4229026.html
The topic of this article is "What is Android", about Android content, from the following points to introduce:
- Android System Architecture
- Andorid released versions
- Android App Features
- Android Development Environment
- Android Program Structure
- Logcat Tools
- Hello World
1,android system Architecture There is a picture of the truth: This is the Android system architecture diagram, enough at a glance, Android can be roughly divided into four layers of architecture, five areas.
- Linux kernel layer (Linux Kernel)
- System operating Layer
- Application Framework layer (application framework)
- Application Layer (applications)
The 1.1,linux kernel-tier Android system is based on the Linux 2.6 kernel, which provides the underlying drivers for various hardware on Android devices, such as display drivers, audio drivers, camera drivers, bluetooth drivers, WiFi drives, power management, and more. 1.2, System operating layer This layer provides major feature support for Android systems through a number of C + + libraries, such as the SQLite library, which provides database support, opengl| The ES Library provides support for 3D drawings, and the WebKit Library provides support for the browser kernel. At the same time, there is the Android Runtime Library, which provides core libraries that allow developers to write Android apps using java. The key is the Dalvik virtual machine, which allows each of our Android applications to run in a separate process, and has a own Dalvik virtual machine instance, compared to the Java Virtual Machine (JVM), Dalvik is specifically for mobile devices, it on the phone memory, CPU performance is limited and so on the situation has been optimized processing. 1.3, application framework layer This layer primarily provides some of the core applications that may be used to build applications that are api,android with these APIs, and developers can build their own applications by using these APIs. For example, there is an Activity manager, view system. Content providers, notification managers, and so on. 1.4, Application layer All applications installed on the phone belong to this tier, such as the system's own contacts, SMS programs, or the programs we download from Google Play, including our own apps. 2,android released version has a picture of the truth: We can see that the latest version of Android is 5.0, called Android 5.0 Lollipop, Chinese Jane called "Lollipop". Since September 2008, Google officially released the Android 1.0 system, which is also the earliest version of the Android system, followed by a number of years, Google has been updated with amazing speed of the release of the Android system, 2.1, 2.2, 2.3 system launched to make Android occupy a lot of market. In February 2011, Google released the Android 3.0 system, which was designed specifically for tablets, but it is also a few of the more unsuccessful versions of Android, after the launch has not seen any improvement, the market share is less pitiful. But soon, in October, Google released the Android 4.0 system, which no longer differentiated between phones and tablets.The distinction can be applied on the mobile phone or on the tablet, in addition to the introduction of a number of features. So what is the current market usage of Android? : Images from the Android user version of Wikipedia since December 2009. Up to May 2014, Android's Jelly Bean was the most widely used version and accounted for 61% of all users. 3,android Application Features
What is the main feature of Android, there are several aspects to reflect:
- Four components
- Rich system controls
- Persistent technologies such as SQLite database
- Location targeting
- Powerful multimedia
- Sensor
3.1, four components What are the four components? Activities, services, broadcast receivers (broadcast receiver), and content Provider are respectively included. The activity is what the Android app looks like, and the user opens the façade of an application and interacts with the user's interface, which is more high-profile. Service, it is relatively low-key, has been in the background silently pay, even if the user quit, the service is still able to continue to run. The broadcast receiver (broadcast receiver) allows your app to receive broadcast messages from everywhere, such as phone calls, text messages, and so on, depending on the broadcast name, to do the corresponding operation, of course, in addition to accept other people sent broadcast messages, they can also send out broadcast messages, Homegrown Content Provider, it is possible to share data between applications, for example, if you want to read the contacts in the system phone book, you need to do so through a content provider. 3.2, rich system controls Android provides a rich system control for developers, we can write beautiful interfaces, or you can extend system controls, customize controls to meet your own needs, Common controls are: TextView, buttion, EditText, some layout controls, and so on. 3.3, persistence technology The Android system also has its own SQLite database, SQLite database is a lightweight, computationally fast embedded relational database. Not only does IT support standard SQL syntax, it can also be manipulated through the Android encapsulated API, making it easy to store and read data. 3.4, geolocation mobile devices and PCs compared to location positioning is a big highlight, now basic Android phones are built with GPS, we can use GPS, combined with our ideas, To build a product based on lbs, is not a cool thing ah, besides, the current hot lbs application is not unfounded, but in the celestial, because the GFW, can only use some localized map API, such as Baidu Map, high-gold map. If one day can use big Google's map, that is tall on AH. 3.5, powerful multimedia Android offers a wide range of multimedia services, such as music, videos, recordings, photos, alarms, and more, all of which can be controlled through code in the program, making your application more colorful. 3.6, sensors There are a number of sensors built into the Android phone, such as acceleration sensors, directional sensors, which are a feature of mobile devices, and we have the flexibility to use these sensors You can make a lot of apps that can't be implemented on your PC. For example, "Shake a Shake" _ You know, "Search songs Shake" and other functions. 4,ANDROID Program Structure
There is a picture of the truth:
See if it is clear, then the next one by one to explain it.
4.1,src There is no doubt that the SRC directory is where all of our Java code is placed, and its meaning here is exactly the same as the SRC directory under ordinary Java projects. 4.2,gen The contents of this directory are automatically generated, there is a R.java file, you add any resources in the project will generate a corresponding resource ID, this file never manually to modify it. 4.3,assets This directory can be used to store a number of files packaged with the program, you can dynamically read the contents of these files while your program is running. In addition, if you use the WebView to load the local Web page, all the pages related files are also stored in this directory. 4.4,bin This directory page does not require much attention, it mainly contains some files that are generated automatically at compile time. Of course, it will include a compiled installation package with the suffix. apk file. 4.5,libs If you use a third-party jar package in your project, you will need to place the jar packages in the Libs directory, and the jar packages placed in this directory will be automatically added to the build path. 4.6,res The contents of this directory is a bit more, simply put, you use in the project all the pictures, layouts, strings and other resources to be stored in this directory, The contents of the R.java mentioned above are also automatically generated according to the files in this directory. Of course, there are many subdirectories under this directory, the images are placed in the drawable directory, the layouts are placed in the layout directory, and the strings are placed in the values directory. 4.7,AndroidManifest.xml This is the configuration file for your entire Android project, and all four components you define in the program need to be registered in this file. You can also add permission declarations to your application in this file, or you can reassign the minimum and target versions of the program that you specified when you created the project. 4.8,proguard-project.txt When you publish your program, some APK files are easy to decompile, so this file works at this point, to confuse your program code, Let others not soEasy to see the source code. 4.9,project.properties Specifies the SDK version 5,logcat tool used when compiling the program
There is a picture of the truth:
Logs play a very important role in the development of any project, and in Android projects you have to use the Logcat tool if you want to view the logs. Android provides a logging tool class that is log, with a total of one rank, and a level increment.
5.1,LOG.V ()
This method is used to print the most trivial, least meaningful log information. The corresponding level verbose is the lowest level in the Android log.
5.2,LOG.D ()
This method is used to print some debugging information that should be helpful for debugging your program and analyzing the problem. The corresponding level of debug, higher than the verbose level.
5.3,LOG.I ()
This method is used to print some of the more important data that you would like to see that can help you analyze user behavior. corresponding level info, higher than Debug.
5.4,LOG.W ()
This method is used to print some warning messages, suggesting that the program may have potential risks in this place, and it is best to fix these warnings. Corresponds to level warn, one level higher than info.
5.5,LOG.E ()
This method is used to print error messages in a program, such as a program entering a catch statement. When the error message is printed, it usually means that your program has a serious problem and must be repaired as soon as possible. The corresponding level of error, higher than the warn level. Small reminder: Customize your own Log tool
For example, you are writing a large project, during which a large number of logs are printed in many parts of the code for ease of debugging. Recently the project has been basically completed, but there is a very troublesome problem, the previous debugging of those logs, the project will continue to print after the official launch, which will not only reduce the efficiency of the program, but also the possibility of some confidential data disclosure.
What do you do, do you want to delete all the print log code in one line? Obviously it's not a good idea, it's not just a time-consuming effort, but it may also be needed in the future when you continue to maintain the project. Therefore, the ideal situation is to be able to freely control the printing of the log, when the program is in the development stage let the log print, when the program is online after the log screen off.
Then we can customize a log tool class to the Android Native tool class package.
public class Logutil {public static final int verbose=1; public static final int debug=2; public static final int info=3; public static final int warn=4; public static final int error=5; public static final int nothing=6; public static final int level=verbose; When a new version is released, the rank is 6 public static void V (String tag,string msg) { if (level <=verbose) { LOG.V (tag, msg); } } public static void D (String tag,string msg) { if (level <=debug) { LOG.D (tag, msg); } } public static void I (String tag,string msg) { if (level <=info) { log.i (tag, msg); } } public static void W (String tag,string msg) { if (level <=warn) { LOG.W (tag, msg); } } public static void E (String tag,string msg) { if (level <=error) { LOG.E (tag, msg); } }}
As you can see, we first defined the six integer constants of VERBOSE, DEBUG, INFO, WARN, ERROR, nothing in Logutil, and their corresponding values are incremented. It then defines a level that is often
, you can specify its value as either of the six constants above. Next we provide five custom log methods of the V (), D (), I (), W (), E (), respectively, within which the LOG.V (), LOG.D (), LOG.I (), LOG.W (), LOG.E () are called to print the log. Only in these custom methods we have added an if judgment, the log will be printed only if the value of the level constant is less than or equal to the corresponding log class value.
This will create a custom log tool, and then in the project we can use the same as the ordinary log tool logutil, such as printing a line of DEBUG level log can be written as follows: LOGUTIL.D ("TAG", "DEBUG log"); Print a line of WARN-level logs to write this: Logutil. W ("TAG", "Warn Log"); Then we only need to modify the value of the level constant, we can freely control the print behavior of the log. For example, the level equals VERBOSE can print all the logs, so that levels equal to WARN can only print the warning above the log, so that it is equal to nothing can be all the logs are blocked off. After using this method, the problem just mentioned is no longer there, you only need to designate level as VERBOSE in the development phase, and when the project is on line, assign level to nothing.
Android System Introduction