Recently, read a book, called "The first line of code", is a blogger written by Csdn, an Android entry-level book, more suitable for beginners. After reading the book, feeling and hair, want to do Android development has been more than a year, but lack of systematic learning, knowledge disorganized, not organized and summarized. So, think I can try to write some articles, to my previous knowledge and work experience to summarize and organize, to sort out their knowledge system. Therefore, there is the birth of this article, if the understanding is not in place, the brothers and sisters in the garden to give the point of error, we discuss together, progress together. I always believe in a word, good things to share, continue to share, until the whole world to warm. The current arrangement is a weekly article, because from the beginning of each article topic thinking, material collection, code validation, mind map design, is very time-consuming, if the problem has not been resolved, it will be postponed to the next week, preferring to slow down, but to ensure that the things written out is original, to people have help. 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 ArchitectureThere is a picture of the truth: This is the Android system architecture diagram, enough at a glance, Android can be roughly divided into four-tier 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, the system run layer this layer through a number of C + + libraries to provide the main features of Android system support, such as the SQLite library 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, the application of the framework layer this layer mainly provides the use of api,android to build the application of some of the core applications are done using these APIs, developers can use these APIs to build their own applications. For example, there is an Activity manager, view system. Content providers, notification managers, and so on. 1.4, Application tier all applications installed on the phone belong to this layer, such as the system comes with the contact person, SMS and other programs, or we download from Google Play programs, including our own development of the application.2,android released versionsThere is a picture of the truth: we can see that the latest Android version 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, the system version no longer differentiate between mobile phones and tablets, can be applied to mobile phones can also be applied to the tablet, in addition to the introduction of many features. So what is the current market usage of Android? : Photo from the Android user version analysis from 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 Development Environment
Development environment to build the necessary software, configuration, etc., I believe we search online search, this kind of article too much. Only a few important tools are highlighted here: Android SDK, Eclipse, ADT.
4.1,android SDK Android SDK Google offers Android Development Kit, when developing Android programs, we need to reference the toolkit, which contains the development of Android app API. 4.2,eclipse development of Java application artifacts, preferably with one of the IDE tools, characterized by open source, super plug-in features, can support multiple language development. Of course, Google also launched Android Studio, specifically for Android programs, but because Android studio was just introduced soon, not too stable, after all, the new tool problem is still more, eclipse is applied is very mature, There are a lot of solutions to eclipse's problems on the web, compared to Android studio. 4.3,adt ADT, called "Android development Tools", is an Eclipse plugin provided by Google to provide a powerful, integrated Android development environment in eclipse.5,android Program Structure
There is a picture of the truth:
See if it is clear, then the next one by one to explain it.
5.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. 5.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. 5.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. 5.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. 5.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. 5.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. 5.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. 5.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. 5.9,project.properties Specifies the SDK version to use when compiling the program6,logcat Tools
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.
6.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.
6.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.
6.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.
6.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.
6.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 classLogutil { Public Static Final intVerbose=1; Public Static Final intdebug=2; Public Static Final intInfo=3; Public Static Final intWarn=4; Public Static Final intError=5; Public Static Final intNothing=6; Public Static Final intLevel=verbose;//Level 6 When new version is released Public Static voidV (String tag,string msg) {if(Level <=VERBOSE) {LOG.V (tag, msg); } } Public Static voidd (String tag,string msg) {if(Level <=DEBUG) {LOG.D (tag, msg); } } Public Static voidI (String tag,string msg) {if(Level <=INFO) {LOG.I (tag, msg); } } Public Static voidW (String tag,string msg) {if(Level <=WARN) {LOG.W (tag, msg); } } Public Static voide (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.7,hello WorldWell, say so much, these are just a few theoretical things, in order to understand more deeply, we have to do the demo, we can go to create a Hello World program to try, with Eclipse+adt help us create the default project is Hello World.
"About Android" first: Android system introduction