Android Basic notes (i)

Source: Internet
Author: User

    • Introduction of 1g-5g
    • Introduction to the Android operating system
    • Android version
    • Architecture of the Android system
    • The difference between two virtual machines
    • Art mode
    • Introduction to Simulators
    • SDK Directory
    • Android Engineering directory structure
    • The process of packaging
    • ADB common directives
    • Case Phone Dialer
    • Four Click events
    • Common layout for Android
    • Units in the Andriod

Introduction of 1g-5g
1st-generation
The representative works are: mobile phone, only voice communication, not to send text messages, more can not surf the Internet.
2nd-generation
The masterpiece is: PHS, can send and receive text messages, Internet access, but the speed of dozens of KPS, and can not be used during the call.
3rd-generation
The rate is typically hundreds of kbps and can be used during calls, keeping the online, mobile internet era coming.
4th-generation (Lte-long time Evolution-long evolution)
Speed of more than 100Kbps, you can watch high-definition video online, upload and download large quantities of data.
5th-generation
The
speed can reach above 1Gbps, almost meet people's all needs.

The biggest difference between them is that the rate is different

Introduction to the Android operating system

Android was developed by Andy Rubin, a system that began just as a smart camera, with the expansion of the mobile phone market moving to the mobile phone operating system.

Android Name: Andy Rubin loves a game of a big ladybird.

Android logo Source: No gender, racial discrimination, designers in the toilet to see the logo on the door, the inspiration generated.

Android version

A few more stable and important versions

version API features
2.3.3 10 Increase NFC payment function, near field sensing function
3.0 11 Optimized for tablets and large-screen devices
4.1.2 16
Architecture of the Android system

4-tier Architecture:
①applications Native Apps: Browsers, desktops, contacts, etc.
②application Framework Intermediate, Java code calls the underlying C code, provides various managers
③libraries (c code base), Android Runtime (Dalvik VM, Libraries c)
④ underlying Linux (security management, memory management, process management, power management, hardware drivers)

Note : Dalvik VM: Virtual machine, Android code running on this virtual machine

The difference between two virtual machines
Why are there two kinds of virtual machines?
Copyright Issues with Sun Corporation
The traditional JVM
write .java files, compile as files .class , package them into .jar files (compile Java source code into a class file, and then package a set of classes into jars)
based on Stack structure , the stack is stored in memory, so memory space is required
Dalvik VMS
Compile files------Package files as files---compile a set of classes into
.java .class .dex .apk a dex file, and then some platforms for higher efficiency will be a Dex converts n multiple class files into a single Dex, so that the execution is faster and more suitable for running on a mobile platform
than a register
-based structure, and registers are in the CPU, so the CPU space is Odex.

See, the different packaging structures in the JVM and the DVM:

Art mode

Art mode through the installation of the application, the program is automatically compiled code pre-read, so that the program directly compiled into machine language, eliminating the Dalvik mode to convert code at all times, to achieve high efficiency, power saving, occupy lower system memory, mobile phone running smooth.
 
But there are always pros and cons, and art solves the problem at the same time: it takes up slightly higher storage space, and the installer has a little longer time to precompile than the normal Dalvik mode.
 
Art mode is a typical case of space-time-changing solutions.

Introduction to the 9 simulator

Common resolution of the device

name resolution Description
Vga 480*640 Standard Video Interface resolution
QVGA 240*320 Only One-fourth of VGA
HVGA 480*320 Only One-second of VGA, use less, development use
WVGA 480*800
Fwvgaq 480:854

Common adaptation resolutions for Android Development:
480 *
*
VM Heap
The memory
of the virtual machine, the memory that each application occupies
Snapshot
snapshots, similar to Win7 's sleep effects. When the emulator is turned off, some active state of the current emulator is saved, and the data is loaded the next time it is started, the boot speed is relatively fast. However, this snapshot has a bug and is not recommended.
Cpu
arm, Intel, if you download Intel's accelerator to choose
to use an Intel accelerator, you need to install an accelerator and download the appropriate image file
Back camera
Back Camera
Webcam
using your computer's webcam
VM Heap
The default size of the DVM, in units of M, for each application that occupies memory
Internal Storage
Phone internal storage size
Use host GPU
with the computer graphics processor, graphics card CPU, computer independent graphics card, you can tick, so the simulator will be quick. Integrated graphics will take the screen
Ram
equivalent to a computer's memory strip, breakpoint data loss
Rom
read-only memory, equivalent to a computer's hard disk, breakpoint data is not lost
SDK Directory
Add-ons
Files that store APIs for advanced applications
Build-tools
Build tools
Docs
Development documentation
Extras
Storage of dependent third-party packages
Platforms
Files for each platform
Sources
Source code file for API
System-images
System's image file
Tools
Tool Files
Android Engineering directory structure
Src
Source Code
Gen
system Auto-generated files
The
various resources in the project are recorded in the R.java, which is equivalent to a dictionary
Android 4.2
the SDK used by the current project
Assets
Asset Catalog
not registered in the R file, packaged into the APK in its entirety
Bin
compiled binaries
includes class, resource file, Dex, APK, manifest file, etc.
Libs
libraries used in the project
Res
system resources, all files generate resource IDs in the R file

①drawable: Picture Resources

  1. DRAWABLE-HDPI: High-resolution picture catalog
  2. DRAWABLE-LDPI: Low-resolution picture Catalog
  3. DRAWABLE-MDPI: Image catalog in medium resolution
  4. DRAWABLE-XHDPI: Large-resolution picture catalog
  5. DRAWABLE-XXHDPI: Ultra-Large resolution picture Catalog
②layout: interface layout
③menu: Menu
④values: String, style, and other data
⑤anim: Animation file
⑥raw: Native file

Androidmanifest.xml
The
four components in the ①android (acticity, ContentProvider, Broadcasereceiver, Service) need to be registered in this file
the permissions required for the ② program also need to be declared in this file
The process of packaging

Packaging with AAPT (Application Android package tools) tools

Deploy to phone, build-and-pack

ADB common directives
Show Connected devices
ADB devices
Display content: Device name, status (Devices, offline)
Importing files to your phone
adb push < mobile target path >
Push
: Push the files on the computer to the simulator
Export files from your phone
adb Pull < phone source file path >
Pull : Pull the files from the simulator to the computer
installation program
adb install
(case) Telephone dialer
//3. Locate the Edit ControlEditText Et_number = (EditText) Findviewbyid (R.id.et_number);//4. Get the phone numberString number = Et_number.gettext (). toString (). Trim ();if(Textutils.isempty (number)) {//ToastToast.maketext (mainactivity. This,"cannot be empty", Toast.length_long). Show ();return;}//5. Call the underlying principle: socket communicationIntent Intent =NewIntent ();//Create an intention: what to doIntent.setaction (Intent.action_call);//6. Set up the call data//Uri includes URLIntent.setdata (Uri.parse ("Tel:"+ number));//Uri: Uniform Resource Identifier, URL: Uniform Resource Locator//7. Open IntentStartActivity (Intent);
164 Click events

Implement the Onclicklistener interface using an internal class to implement the

Private  class MyButton implements Onclicklistener {    @Override     Public void OnClick(View v) {//3. Locate the Edit ControlEditText Et_number = (EditText) Findviewbyid (R.id.et_number);//4. Get the phone numberString number = Et_number.gettext (). toString (). Trim ();if(Textutils.isempty (number)) {//ToastToast.maketext (mainactivity. This,"cannot be empty", Toast.length_long). Show ();return; }//5. Call the underlying principle: socket communicationIntent Intent =NewIntent ();//Create an intention: what to doIntent.setaction (Intent.action_call);//6. Set up the call data        //Uri includes URLIntent.setdata (Uri.parse ("Tel:"+ number));//Uri: Uniform Resource Identifier, URL: Uniform Resource Locator        //7. Open IntentStartActivity (Intent); }}

Implemented by anonymous inner classes

// 实现点击事件的第二种方式:匿名内部类btn_call.setOnClickListener(new OnClickListener() {    @Override    publicvoidonClick(View v) {        callPhone();    }});

To implement a listening interface by a class file

 Public  class mainactivity extends Activity  implements  Onclicklistener {    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//1. Find the buttonButton 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 a third way to click eventsBtn1.setonclicklistener ( This); Btn2.setonclicklistener ( This); Btn3.setonclicklistener ( This); Btn4.setonclicklistener ( This); Btn5.setonclicklistener ( This); }Private void Callphone() {//3. Locate the Edit ControlEditText Et_number = (EditText) Findviewbyid (R.id.et_number);//4. Get the phone numberString number = Et_number.gettext (). toString (). Trim ();//5. Call the underlying principle: socket communicationIntent Intent =NewIntent ();//Create an intention: what to doIntent.setaction (Intent.action_call);//6. Set up the call data        //Uri includes URLIntent.setdata (Uri.parse ("Tel:"+ number));//Uri: Uniform Resource Identifier, URL: Uniform Resource Locator        //7. Open IntentStartActivity (Intent); }@Override     Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.button1:callphone (); Break; CaseR.id.button2: Break; CaseR.id.button3: Break; CaseR.id.button4: Break; CaseR.ID.BUTTON5: Break;default: Break; }    }}

Add the OnClick property to the layout file, adding the corresponding method in the code, and passing in the view parameter

Registering a click event in a layout file

<Button        android:onClick="click"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/et_number"        android:layout_below="@+id/et_number"        android:layout_marginTop="32dp"        android:text="拨打" />

Add a corresponding method to your code

// 按钮的第四种点击事件,原理:利用的反射技术// 第四种方式缺点:莫名其妙publicvoidclick(View v) {    callPhone();}
Common layout for Android
Linear layout
horizontal, vertical display, if there are multiple components, exceeding the screen size, the excess is not displayed
you can define the direction by Android:orientation.
android:orientation= "Horizontal" indicates horizontal orientation
android:orientation= "Vertical" indicates vertical direction
Relative layout
The
relative layout is one of the most common layout methods in the actual layout.
relative layouts are used in XML files to define them.
relative layouts can set the location of a view relative to other views, which can include up and down, and so on, so it is much more flexible than other layouts.
relativelayout are the following: First class: The property value is True or False for Android: Layout_centerhrizontal horizontally centered android:layout_centervertical vertically centered android:layout_centerinparent Android with respect to the parent element: Layout_alignparentbottom snaps to the bottom edge of the parent element Android:layout_alignparentleft snaps to the left edge of the parent element android:layout_alignparentright Snaps to the right edge of the parent element Android:layout_alignparenttop snaps to the top edge of the parent element the second class: The attribute value must be the reference name of the id "@id/id-name" Android:layout_below under an element of Android : Layout_above above an element android:layout_toleftof on the left side of an element android:layout_torightof to the right of an element android:layout_aligntop  The top edge of this element and the top edge of an element are aligned android:layout_alignleft the left edge of this element and the left edge of an element are aligned android:layout_alignbottom the bottom edge of this element and the bottom edge of an element Android:layout_alignright the right edge of this element and the right edge of an element are aligned to the third class: The attribute value is the specific pixel value android:layout_marginbottom the distance from the bottom edge of an element android:layout_ MarginLeft the distance from the left edge of an element android:layout_marginright the distance from the right edge of an element android:layout_margintop the distance from the top edge of an element  
Table layout
Less use of
Frame layout
frame layouts are one of the simplest layout types to organize controls in the user interface of an Android program.
frame layouts are used in XML files to define them.
a
child view in a frame layout is always drawn to the upper-left corner of the screen, and all views added to the layout are displayed as cascading, the first view added to the frame layout appears at the bottom, the last one is placed on top, and the previous view overrides the next layer of view. Similar to the DIV in HTML.
在框架布局中,常用的属性有以下几项:  android:top    将视图放到屏幕的顶端  android:Buttom 将视图放到屏幕的低端  android:Left   将视图放到屏幕的左端  android:Right  将视图放到屏幕的右端  android:Center_vertical   将视图按照垂直方向居中显示  android:Center_horizontal 将视图按照水平方向居中显示
Units in the Andriod
Dip
abbreviation: DP
a density (density) based abstract unit, which is related to the device hardware, usually in the development of some view of the width of the recommended use of this, in general, at different resolutions, there will be no zoom feeling.
at run time, Android transparently handles the scaling of any desired dip units based on the actual density of the screen in use.
do not rely on device pixels, according to the device automatically adapt to size, recommended to use
Sp
Similar to DIP/DP, it is scaled based on the user's font size preference, specifically for setting the font size
Px
pixels, which are the physical pixels of the screen, are density-related and have a large density, with more PX per unit area. There are different effects at different resolutions and this is not usually recommended.

Android Basic 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.