Android basic notes (1)

Source: Internet
Author: User
Tags sleep function

Android basic notes (1)

1G-5G introduction to the Android operating system introduction to the Android version Android system architecture introduction to different ART-Mode Simulators of two virtual machines SDK directory Android project directory structure packaging process ADB Common commands case: Phone Dialers, four click events, Android, common layout, Andriod, Unit

1G-5G introduction the masterpiece of 1st-Generation is: dashboard, which can only communicate via voice, cannot send text messages, and cannot access the Internet. The 2nd-Generation masterpiece is: PHS, which can send and receive text messages and access the Internet, but the speed is dozens of Kps and cannot be used during calls. The 3rd-Generation speed is usually several hundred Kbps and can be used during calls to stay online. The mobile Internet era is approaching. The 4th-Generation (LTE-Long Time Evolution-Evolution over Kbps) Speed allows you to watch HD videos online and upload and download large volumes of data. The 5th-Generation speed can reach more than 1 Gbps, satisfying almost all people's needs.

The biggest difference between them is: Different speed

Introduction to the Android operating system

Android was developed by Andy Lubin. It was originally a smart camera system and switched to the mobile operating system as the mobile phone market expanded.

Android name: Andy Lubin enjoys a big ladybug in the game.

Android Logo Source: requires no gender or racial discrimination. Designers can see the Logo on the toilet door when they go to the toilet, which is the inspiration.

Android version

Several stable and important versions

Version API Features
2.3.3 10 Added NFC payment and near-field sensing functions
3.0 11 Optimized for tablets and large screen devices
4.1.2 16
Android Architecture

4-layer architecture: ① Applications native Applications: browsers, desktops, contacts, etc. ② Application Framework intermediary, java code calls the underlying c Code, provides various managers ③ Libraries (c code library ), android Runtime (Dalvik VM, Libraries C) ④ underlying Linux (security management, memory management, process management, power management, hardware driver)

Note:: Dalvik VM: virtual machine. The android code runs on this virtual machine.

Why are there two different virtual machines? Copyright of Sun: Traditional JVM Compilation .javaFile-> compile .classFile-> package .jarFile (compile the java source code as a class file, and then package a group of classes into jar) based on Stack structureStack is stored in the memory, so the memory space Dalvik VM is required to write .javaFile-> compile .classFile-> package .dexFile-> package .apkFile (compile a group of classes into a dex file, and some platforms convert a dex file to an odex file for higher efficiency, and compile N multiple class files into a dex file, in this way, the execution efficiency is faster and more suitable for running on mobile platforms. RegisterIn the CPU, so the CPU space is used.

See the different packaging structures in JVM and DVM:

ART Mode

The ART mode automatically pre-reads and compiles the program code when installing the application, so that the program can be directly compiled into a machine language, eliminating the need to convert the code from time to time in the Dalvik mode, high efficiency, power saving, low system memory usage, and smooth operation of mobile phones.
 
However, there are always two sides in everything. ART solves this problem while at the same time: it will occupy a slightly higher storage space, and it takes some time for the installation program to implement pre-compilation than the ordinary Dalvik mode.
 
The ART mode is a typical case of changing the space for time.

9 Introduction to simulators

Common device resolutions

Name Resolution Description
VGA 480*640 Standard video interface resolution
QVGA 240*320 Only the VGA 1/4
HVGA 480*320 Only 1/2 of VGA, less used, Development and Use
WVGA 480*800
FWVGAQ 480: 854

Commonly used adaptation resolution for Android development: 480*8001280*800 VM Heap VM memory, each application occupies a Snapshot of the memory Snapshot, similar to the sleep function of win7. When the simulator is disabled, some active statuses and data of the current simulator will be saved. The information will be loaded at the next startup, and the startup speed will be faster. However, this snapshot has a bug and is not recommended. CPUarm and intel. If you want to use the intel accelerator only after downloading the intel accelerator, you need to install the accelerator and download the corresponding image file Back camera Webcam uses the default size of the computer's camera VM HeapDVM, the Unit is M. The memory occupied by each application is the Internal Storage size of the mobile phone. Use host GPU to Use the computer's graphics card processor, graphics card cpu, and computer independent graphics card. You can check this option so that the simulator will be faster. The integrated graphics card will display a screen of RAM, which is equivalent to a computer's memory, and the breakpoint data is lost in the ROM read-only memory, which is equivalent to a hard disk of the computer, resumable data is not lost. The SDK directory add-ons is used to store files of APIs of advanced applications. build-tools build tool docs development documentation extras is used to store source code files of dependent third-party packages on various platforms of platforms. system-images system Image File tools file Android project directory structure src Source Code gen system automatically generated file R. java records various resources in the project, which is equivalent to a dictionary Android 4.2. The SDKassets asset directory used by the current project is not registered in the R file, the binary files compiled by bin in the APK include the library res system resources used in the libs project, such as class, resource file, dex, apk, and inventory file, all files generate resource IDs in the R file.

① Drawable: image resources

Drawable-hdpi: drawable-ldpi: drawable-mdpi: drawable-xhdpi: drawable-xxhdpi: ultra-high-resolution image directory ② layout: interface layout ③ menu: menu ④ values: String, style, and other data ⑤ anim: animation file ⑥ raw: Native File
AndroidManifest. xml ① the four components (Acticity, ContentProvider, BroadcaseReceiver, and Service) in Android need to register the permissions required by the program in this file. The packaging process must also be declared in this file.

Use the aapt (application android package tools) tool to package

Compile-> package-> signature-> adb-> deploy on your mobile phone

ADB Common commands show connected device adb devices display content: device name, status (device, offline) Import file to mobile phone adb push <手机目标路径> Push: Push files on the computer to the simulator to export files from the mobile phone adb pull <手机源文件路径> Pull: Pull the files in the simulator to the computer installer adb install (CASE) telephone dialer
// 3. find the edit Control EditText et_number = (EditText) findViewById (R. id. et_number); // 4. obtain the phone number String number = et_number.getText (). toString (). trim (); if (TextUtils. isEmpty (number) {// Toast. makeText (MainActivity. this, "cannot be blank", Toast. LENGTH_LONG ). show (); return;} // 5. underlying principle of dialing: socket Communication Intent intent = new Intent (); // create an intent: What do you want Intent to do. setAction (Intent. ACTION_CALL); // 6. set the dialing data // Uri including Urlintent. setData (Uri. parse ("tel:" + number); // Uri: Uniform Resource Identifier, Url: Uniform Resource Identifier // 7. enable startActivity (intent );
16. Four click events

Implement OnClickListener using internal classes

Private class MyButton implements OnClickListener {@ Override public void onClick (View v) {// 3. find the edit Control EditText et_number = (EditText) findViewById (R. id. et_number); // 4. obtain the phone number String number = et_number.getText (). toString (). trim (); if (TextUtils. isEmpty (number) {// Toast. makeText (MainActivity. this, "cannot be blank", Toast. LENGTH_LONG ). show (); return;} // 5. underlying principle of dialing: socket Communication Intent intent = new Intent (); // create an intent: What do you want Intent to do. setAction (Intent. ACTION_CALL); // 6. set the dialing data // Uri including the Url intent. setData (Uri. parse ("tel:" + number); // Uri: Uniform Resource Identifier, Url: Uniform Resource Identifier // 7. enable startActivity (intent );}}

Implemented through anonymous internal classes

// Second method for implementing click events: anonymous internal class btn_call.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {callPhone ();}});

Listener interface implemented by class files

Public class MainActivity extends Activity implements OnClickListener {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // 1. find the Button btn1 = (Button) findViewById (R. id. button1); Button btn2 = (Button) findViewById (R. id. button2); Button btn3 = (Button) findViewById (R. id. button3); Button btn4 = (Button) findViewById (R. id. button4); Button btn5 = (Button) findViewById (R. id. button5); // set the third method of the Click Event btn1.setOnClickListener (this); listener (this); btn3.setOnClickListener (this); btn4.setOnClickListener (this); btn5.setOnClickListener (this );} private void callPhone () {// 3. find the edit Control EditText et_number = (EditText) findViewById (R. id. et_number); // 4. obtain the phone number String number = et_number.getText (). toString (). trim (); // 5. underlying principle of dialing: socket Communication Intent intent = new Intent (); // create an intent: What do you want Intent to do. setAction (Intent. ACTION_CALL); // 6. set the dialing data // Uri including the Url intent. setData (Uri. parse ("tel:" + number); // Uri: Uniform Resource Identifier, Url: Uniform Resource Identifier // 7. enable startActivity (intent);} @ Override public void onClick (View v) {switch (v. getId () {case R. id. button1: callPhone (); break; case R. id. button2: break; case R. id. button3: break; case R. id. button4: break; case R. id. button5: break; default: break ;}}}

Add the onclick attribute to the layout file, add the corresponding method to the Code, and input the View parameter.

Register click events in the layout File

 

Add the corresponding method to the code

// The fourth click Event of the button. The principle is reflection. // The fourth disadvantage is that public void click (View v) {callPhone ();}
Android uses linear layout to display horizontally and vertically. If multiple components exceed the screen size, android: orientation can be used to define the direction for android: orientation = "horizontal" indicates horizontal direction android: orientation = "vertical" indicates relative vertical direction layout relative layout is one of the most common layout methods in actual layout. Relative layout is defined in xml files. You can set the position of a view relative to other views. These positions can include the upper, lower, and lower sides. Therefore, they are more flexible than other layout methods.
Common Properties of RelativeLayout include: Class 1: true or false android: layout_centerHrizontal horizontal center android: layout_centerVertical vertical center android: layout_centerInparent relative to parent element completely center android: attaching the lower edge of the parent element android: layout_alignParentLeft attaching the left edge of the parent element android: layout_alignParentRight attaching the right edge of the parent element android: layout_alignParentTop attaching the upper edge of the parent element type 2: the property value must be the reference name "@ id/id-name" of the id. android: layout_below is at the bottom of an element. android: layout_abve is at the top of an element. android: layout_toLeftOf on the left of an element android: layout_toRightOf on the right of an element android: layout_alignTop the top edge of this element is aligned with the top edge of an element android: the left edge of the layout_alignLeft element is aligned with the left edge of an element. android: layout_alignBottom: the bottom edge of the element is aligned with the bottom edge of an element. android: layout_alignRight: the right edge of an element is aligned with the right edge of an element. Category 3: The attribute value is the specific pixel value. android: layout_marginBottom: distance from the bottom edge of an element. android: layout_marginLeft distance from the left edge of an element android: layout_marginRight distance from the right edge of an element android: layout_marginTop distance from the edge of an element
Table layout uses a relatively small frame Layout Framework layout, which is one of the simplest layout types to organize controls on the Android user interface. The framework layout is defined in the xml file. The child views in the frame layout are always drawn to the upper left corner of the screen. All the views added to this layout are displayed in a stacked manner, the first view added to the Framework layout is displayed at the bottom layer, and the last view is placed at the top layer. The view on the top layer overwrites the view on the next layer, similar to the div in html.
In the Framework layout, the following attributes are commonly used: android: top: Put the view to the top of the screen android: Buttom put the view to the low-end android of the screen: left: place the view to the Left of the screen. android: Right: place the view to the Right of the screen. android: Center_vertical: center the view vertically. android: Center_horizontal: center the view horizontally.
The Unit dip in Andriod is abbreviated as "dp". It is an abstract unit based on density (density). This is related to the hardware of the device. It is recommended to set the width and height of some views during development, in general, there is no sense of scaling at different resolutions. At runtime, Android transparently scales any required dip units based on the actual screen density in use. Depending on the device pixel, the device automatically adapts to the size. sp is recommended to be similar to dip/dp, and will be scaled based on the user's font size preferences. It is used to set the font size px pixels, it is the physical pixel of the screen, which is related to the density. The density is high, and there will be more pixels per unit area. It has different effects at different resolutions, which is not recommended.

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.