Android Learning notes (i)

Source: Internet
Author: User

Objective:

Recently wanted to learn Android development, summer after the school recruit may be looking for Android work. The textbook I chose was written by Guo Lin's predecessor, "The first line of code", which was published in 14, and before the publication, Guo Lin's blog has accumulated a lot of popularity on CSDN. because I have a lack of understanding of Android, usually also rarely pay attention to CSDN technology blog, so I am this time to learn Android, only to understand Guo Lin predecessors, understand this book, deeply ashamed. I decided to write down the process of learning this book as a learning note, on the one hand, in the process of blogging to make a deposit of learning knowledge, on the other hand, if my blog is fortunate enough to be seen by other beginners, may be able to help them. If I could be seen by my predecessors, it would help me to point out the flaws in my blog.

The first chapter begins with your first line of Android code

an Android system architectureTo learn Android programming, it is best to first understand the Android system architecture, as shown in four levels.
    • Linux kernel layer: This layer provides drivers for a variety of hardware
    • Library: Includes system runtime Library (Android Runtime) and C/C + + library (Libraries)
    • Application Framework: Provides various APIs that an application may use
    • Application layer: All Applications

More specific content can be found in the blog of Wu Qin seniors http://www.cnblogs.com/skynet/archive/2010/04/15/1712924.html

two Android four componentsThe specific role of these four components, the following chapters will be mentioned, I would like to skip the first.
    • Activity: The façade of all Android apps, what you can see in the app, is in action.
    • Service: Users cannot see and run silently in the background.
    • Broadcast receivers (broadcast receiver): Allows programs to receive broadcast messages from everywhere, and programs can send broadcasts out.
    • Content Provider: Enables you to share data between applications.
three project composition in Android studioThe programming environment used in Guo Lin's predecessors was eclipse, and I used Android Studio,android Studio to provide a variety of architectures (Android, Project files, etc.), my personal favorite is Android, This is also the default structure, which I will introduce based on the Android structure.
    • Manifests: Store the Androidmanifest.xml profile, which is the configuration file for the entire Android project, and all four components used in the project must be registered here.
    • Java: The source code of the project, and now there is only one single mainactivity file in this newly created project.
    • Res:resource's abbreviation for storing various resource files. Layout files are stored in layouts, drawable and mipmap are used to store images, and drawable,values are used to store strings. Each picture inside drawable, there are several different resolution copies, in order to be compatible with different models or versions.
Four preliminary exploration of the HelloWorld project I created a HelloWorld project, the content of the newly created project is simple, we only need to study the activity_ in Androidmanifest.xml, mainactivity, Layout folder Main.xml, strings.xml Four files in the values folder. 1, Androidmanifest.xml:We only look at the android:label= "@string/app_name" line, which indicates that the item's label is stored in Strings.xml, and the name of the string (equivalent to the ID of a string, which can be found by this ID) is APP_  Name Open Strings.xml, you can see sure enough to store a string named App_name, the specific contents of the string is: HelloWorld at this time if the project to generate an apk, download to the phone to install, you will find the app's name is called HelloWorld, If you modify the string contents of App_name to Goodbye, then the name of the app is goodbye.

Back to Androidmanifest.xml, you can see <activity .... </activity> this group of content, which is to register mainactivity this activity, Activities that are not registered in the Androidmainifest.xml are not available.

<intent-filter> This tag has two lines of code, the role of these two lines of code indicates that activity is the main activity of the project, you open the app, the first thing you see is this activity.

About <activity> and <intent-filter> how to use, will be mentioned again later.

  

  2, Mainacitivity:

  

This is the only source code currently available for the project, Mainacitivity inherits from the Appcompatactivity class, which is the active base class provided by the Android system. Mainacitivity overrides the base class's OnCreate method, which is a method that must be executed when each activity is created, because each activity must have a corresponding layout file, and it has to read the layout file to know how to lay out its own interface.

We look at this line of code: Setcontentview (r.layout.activity_main), this line of code reads a layout file named Activity_main.xml to layout, we go to Activity_main.xml file to see.

  3, Activity_main.xml:

  

You can see that the layout file defines a <TextView> control, which is a text control, specifically how to use the first skip to talk, only see android:text= "Hello world!" Here, the contents of the double quotes will be displayed as text in the app activity screen, and if you modify the content here, the content displayed on the app will change. It is important to note that the Android program is designed with logical and view separation and is not recommended for hard-coded use. So, here's Hello world!, we'd better take it to Strings.xml, as mentioned above App_name, we can add <string name= "Hello_world" in Strings.xml > Hello World!</string> and then android:text= "Hello world!" Change to android:text= "@string/hello_world" as follows:

  

  

This makes the whole logic more clear, and the string can be managed uniformly.

  4, Strings.xml:

After reading the above, you should already know the role of this file, that is, where the string is stored.

Android Learning notes (i)

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.