Explore the art of Android development

Source: Internet
Author: User

Explore the art of Android development
1 Activity life cycle and startup mode

Life cycle in the typical case
Life cycle under exceptional circumstances

Startup mode
Standard mode
Stack Top multiplexing Mode
In-Stack reuse mode
Single-instance mode

The flags of activity
Matching rules for Intentfilter

2 IPC mechanisms

Inter-process communication

Serializanle
Parcelable
Binder


3 View Event System

Event distribution mechanism

Event distribution mechanism
Click event is the Motionevent event distribution is actually the distribution of the Motionevent event
Three main methods
Dispatchtouchevent distribution
Onintercepttouchevent Intercept
Ontouchevent consumption
Event Delivery Order Activity Window View
After the ViewGroup Click event is generated, it calls Dispatchtouchevent and then calls Onintercepttouchevent
If TRUE indicates that the event is to be intercepted, the ontouchevent is called
Returns false to indicate that the event is passed to its child element if it is not seen


How the 4 view works

Work flow of view

Onmeasure calculate the actual size for the entire view tree set the actual width height
The actual aspect height of each view control is determined by the parent view and the view itself
OnLayout view is placed in the appropriate location based on the child view size layout parameters
OnDraw draw the image first draw the background and then call OnDraw to draw the view itself if view is ViewGroup
Call dispatch to draw a child view and draw the scroll bar last

Custom View

Inherit view rewrite OnDraw to achieve some irregular effects
Inheritance ViewGroup derived special layout for implementing custom layouts


5 Remoteviews
6 drawable
7 Android Animations

The View animation transforms the zoom rotation transparency by making an image transformation of the object in the scene to produce an animated effect.
Frame Animations play a series of images in sequence to produce animation effects
Property animation API11 Animate the properties of a dynamically changing object


8 Window WindowManager
94 working mechanism of large components
Android's messaging mechanism

Handler mechanism
Handler messages are placed in message queue MessageQueue by calling SendMessage
Looper is responsible for taking the message out of the message queue and re-handing it to handler for processing.
11 Threads and Thread pools

Asynctask
Encapsulates the thread pool and handler to make it easy to update the UI in a child thread

Handlerthread
Use handler inside threads with message loops
The implementation is done by creating a message queue through Looper.prepare in run and opening the message loop through Looper.loop

Intentservice
Special service encapsulates the Handlerthread and handler used to perform the time-consuming task of automatically stopping after task execution

Threadpoolexecuter thread Pool
Reusing thread pools threads avoid performance overhead due to thread creation destruction
Effective control of the maximum number of threads pool concurrency prevents blocking caused by preemption of resources between threads
Ability to manage threads with ease

Constructor method parameters
Corepoolsize Number of core threads
Maxmunpoolsize Maximum number of threads
KeepAliveTime Super Time
Unit time Units
WorkQueue Task Queue
Threadfactory Thread Factory

Four types of thread pools
Fixedthreadpool
Cachedthreadpool
Scheuledthreadpool
Singlethreadpool


Load and cache of bitmap

Bitmap Loading and caching

LruCache Memory Cache
Internally uses LINKEDHASHMAP to store external cache objects in a strongly referenced manner
Strongly referencing a direct object reference
The object is recycled by GC when the soft reference system is low on memory
A weak reference to this object will be recycled by GC at any time

Disklrucache Hard Disk Cache


13 Integrated Technology

Crashhandler

Multidex resolution number out of bounds

Dynamic Loading Technology
Resource access
Activity Life Cycle Management
ClassLoader Management

Anti-compilation preliminary


JNI and NDK

JNI Java Native Interface facilitates Java calls to a layer of interfaces encapsulated in native code such as C C + +
NDK Android offers a collection of tools that can be made easier on Android with the NDK
Access to local code via JNI

The development process for JNI
Declaring the native method in Java
Compile the Java source file to get the class file and then export the JNI header file via Javah
Implementing the Jni Method
Compiling the so library and invoking it in Java

NDK Development process
Download and configure the NDK
Create an Android project and declare the required native method for the Java file system.loadlibrary
Implement the native method declared by the Android project Test.cpp android.mk application.mk
Generate so library with ndk-build command compilation

Data types and type signatures for JNI
The process of JNI calling a Java method


Android Performance optimization

Performance optimization
Layout optimization
Remove unused controls and hierarchies in the layout select low-performance ViewGroup avoid over-painting
The include tag reuses the specified layout file
Merge label and include tag use to reduce layout hierarchy
Viewstub loading the required layout files on demand

Drawing optimization
View OnDraw avoid doing a lot of work
Do not create new local objects do not take time-consuming tasks

Memory leak Optimization
memory leaks due to static variables
Singleton mode causes
Property animation Infinite Loop
Supplement
The resource object is not closed, such as querying the database without closing the cursor
Construction adapter does not use Convertview
bitmap does not call recycle free memory when not in use
Context Escape
registration is not canceled such as dynamic registration broadcast in activity destruction no anti-registration
Collection Object Not cleaned
use non-static inner classes in activity and open a long-running thread
activity cannot be recycled because the inner class holds activity references
handler memory leaks
the static variables of the class hold big Data Objects
static instances exist for non-static inner classes

response speed optimization avoids time-consuming operations in the main thread
anr
activity cannot respond to input operation within 5 seconds
Span style= "font-family: Song body; font-size:12px ">broadcastreceiver within 10m seconds has not finished operation

Positioning development Machine View Traces.txt logs
Span style= "font-family: Song body; FONT-SIZE:12PX "> Avoid using sub-threading to process time-consuming IO operations
solution
java multithreaded
asynctask
handler mechanism
handlerthread
Span style= "font-family: Song body; font-size:12px ">intentservice

ListView optimization
Take Viewholder and avoid time-consuming operations in GetView
Controls how often tasks are executed based on the sliding state of the list
Turn on hardware acceleration to make the ListView slide more process

Bitmap optimization
Use bitmapfactory.options to sample pictures as needed
Configuring the Insamplesize parameter

Threading optimization
Using a thread pool

MAT Memory Leak Analysis tool

Provider maintainability

Explore the art of Android development

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.