[Android] HelloWorld for Android Development

Source: Internet
Author: User

Introduction: this problem was found during Unity development. Although Unity is cross-platform, it can be developed for Android, IOS, Web, and PC, however, to implement something slightly at the system layer, you still need to call the original system interface (custom Interface) through communication for development, therefore, we still need to know about the original development of other platforms. Before that, I had some knowledge about Web and IOS development. Recently, I want to implement the QR code scanning function of a mobile platform, I am not familiar with the development of Android platform because I cannot perform real-machine debugging under the current resources of IOS, so I feel a headache, so I made up my mind to learn about the original Android development, asking people to depend on themselves, asking people only for the time being, and those who have patience cannot go through your repeated questions, others also have others' jobs!

Learning a new technology begins with HelloWorld! As we all know, entering HelloWorld is the door to development! Next I will write my learning experience!

I have been engaged in the development of Visual Stdio software, whether it is cocos2dx or. net and Unity3d are inseparable from VS. I feel that Microsoft is the most successful not only in the Windows operating system, but also in the Visual Stdio integrated development environment. I have never touched java-related development directions before, it is because we are used to VS and fall in love with it, so we are not used to the Eclipse development environment. java developers may also feel this way. We are used to the Eclipse development environment just like it. Now, we have to learn about Android development, so we are still getting used to using Eclipse. The obvious difference between Eclipse and the other two integrated development environments (Xcode and VS2010) is that the configuration is cumbersome, impatient programmers may be stuck on the way to configuration. However, patience, care, and responsibility are essential qualities for programmers! Here, we will not describe how to configure the Android development environment, such as Baidu. The next step is to start creating HelloWorld!

I. Introduction to adb, an important debugging tool

Adb (android debug bridge) android debug bridge opens the Android SDK directory and introduces the important adb tool. The internal tcp debug bridge uses socket and simulator to perform the specified operation.
. Adb is a very important tool. We often use it for debugging. We can add it to the environment variable, configure the operation: My computer-> right-click-> properties-> advanced-> environment variable

Then you can use the adb tool in cmd.


Adb basic operations
A) copy the local file to your mobile phone.
Adb push [source file] [target file]
Adb push 1.txt/mnt/sdcard/1.txt
B) copy the mobile phone file to the local device.
Adb pull [source file] [local]
Adb pull/data/app/Apidemos.apk C: \ demo.apk
C) Killing a process
Adb kill start-server
D) install a desktop application (apk) on the mobile phone simulator.
Adb install demo.apk
E) uninstall an application
Adb uninstall package name (process name)
Adb uninstall com. example. android. apis
In fact, the app vivo pods QQ mobile phone shutdown 91 mobile assistant is to encapsulate these commands and then execute the corresponding operations
F) view the adb version.
Adb version (many inexplicable problems may be caused by the adb version)
G) view the information of all devices connected to the current device.
Adb devices (if it is connected to a real machine, the name of the real machine will also be displayed)
H) Go to the console of the simulator or real machine.
Adb shell
The Android phone is actually the console of the Linux operating system
Ls view directory information
Ps to view information about the currently running process
Kill to kill a process.
# Kill 127 (pid process number)
These are all linux commands, so we will not detail them!
Ctrl + f11 switch screen portrait

Ii. HelloWorld development 1. Basic Creation

File-> New-> Android Application Project


Generated directory

2. generated directory Parsing

Project. properties folder
Android. jar version used for development
Android-17 Android 4.2.2
Android-8 Android 2.2

The correspondence between API level and NDK is as follows:

Code name Version API level
(No code name) 1.0 API level 1
(No code name) 1.1 API level 2
Cupcake 1.5 API level 3, NDK 1
Donut 1.6 API level 4, NDK 2
Eclair 2.0 API level 5
Eclair 2.0.1 API level 6
Eclair 2.1 API level 7, NDK 3
Froyo 2.2.x API level 8, NDK 4
Gingerbread 2.3-2.3.2 API level 9, NDK 5
Gingerbread 2.3.3-2.3.7 API level 10
Honeycomb 3.0 API level 11
Honeycomb 3.1 API level 12, NDK 6
Honeycomb 3.2.x API level 13
IceCreamSandwich 4.0.1-4.0.2 API level 14, NDK 7
IceCreamSandwich 4.0.3 API level 15


AndroidManifest. xml
Register the information we applied to the Android system, which is equivalent to the Registry.
Registered package name and version number
Node is the main interface of our application
Modify the icon to add node Information
Add a new drawablefile in the resfile to save the image folder, and put a 5.png icon
Android: icon = "@ drawable/5"

Res folder
Strings. xml in the values folder indicates that the app name has been started. Modify the app name here.
Activity_main.xml in the layout folder is the interface layout file. Click GraphicalLayout to preview the interface,

Click activity_main.xml to modify the text information and change it to "Android development, I want to conquer you"


For resource configuration information in all res files, we will have an R. java, which is automatically generated by the aadt tool and all exist in the form of an int type reference. In res/values/strings. add a node under xml Ding Xiaowei

Then go to the R file and you will find that
Public static final int myname = 0x7f050003;


Role of the R file: In order to facilitate repeated use of the defined resource file in the program, so that the program and the resource are separated, then let's explain the previously written android: icon = "@ drawable/5 ".
@ Indicates the R file. drawable indicates the internal class of the R class. 5 indicates the icon of the address pointed to by 5 in the internal class.
All in all, the res resource file R file will automatically generate an int type node information to agree to manage resources.

Finally, we will introduce the most critical src (source code folder)/MainActivity file. Every Activity in Android development corresponds to this interface.
Analogy: During jsp development ,. jsp files correspond to a webpage that users can see ;. net development ,. the aspx file is also a dynamic web page that you can see. The MVC mode is used here, and the Activity class is used to implement the user's visible interface.
Double-click the MainActivity. java file to see the onCreate method, which is executed when the application is started for the first time. There is such a piece of code
SetContentView (R. layout. activity_main); this is to set the activity layout. We can customize the layout and drag some controls to the activity.

The layout is the activity_main resource under the layout node under the R file, corresponding to the res/layout/activity_main.xml file. The most important thing for Android development is the R file.

Common Errors:
1. For example, if the android: name in the Registry File AndroidManifest. xml is wrong, an error will be reported during system startup because the system first accesses the Registry file,
The system cannot find the corresponding activity because of an error in the configuration of the list file.
2. AndroidManifest. xml




Role of this configuration file: generate an application icon in the luncher program. If we delete the icon and restart it, the log will show that HelloWorlddown is successfully installed, however, clicking the application icon prompts us that the application has not been installed!








Zookeeper

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.