The understanding of White Dragon Guardian + asynchronous message
手机卫士
MobileSafe
Mobilesafe 1.0
- Splash interface (set a gradient animation)
- Load the count-in interface only,–> home page
According to the Function module Division
Activity com.itheima.mobilesafe.activty
Background services com.itheima.mobilesafe.service
Broadcast recipient com.itheima.mobilesafe.receiver
Database com.itheima.mobilesafe.db.dao
Object (Java Bean) com.itheima.mobilesafe.domain/bean
Custom Controls com.itheima.mobilesafe.view
Tool Class com.itheima.mobilesafe.utils
Business logiccom.itheima.mobilesafe.engine
Problem area
1. listView
Adapter Loading principle completed
2. The principle of asynchronous loading,
3. Get started to a proficient blog after reading
4. Animation review
Problem solving
the principle of asynchronous loading
Why cannot be created in a sub Handler
-thread, because there is the following code in the constructor method
mLooper = Looper.myLooper();
ifnull) {
thrownew RuntimeException(
"Can‘t create handler inside thread that has not called Looper.prepare()");
}
You can see that the constructor has been called once Looper
if it is empty and throws the run-time exception. Note that when the system is in the main thread, we call a Looper.prepare()
method. and the underlying role of the method new Looper()
,
Summary: The handler object can be created directly in the main thread, and Looper.prepare () must be called first in the child thread to create the handler object.
Looper Collective Source Interpretation
Handler
is how to accept the message sent by sending a message sendMessage(msg)
to the Send message method will eventually be called into the sendMessageAtTime()
method, the source of the method of the meaning is that the message in a message queue MessageQueue
let us send the message in the form of a queue, And this class is created in a way that is sufficient for the method, so one of Looper
us Looper
corresponds MessageQueue
to one, and their arrangement is arranged in chronological order.
The last looper.loop
method will have a dead loop inside call a dispatchMessage(msg)
method to call handleMessage()
so that we can access the main thread in the asynchronous message UI.
Learning experience
- Note that each time you write the code, notice whether the fragment is
null
- When customizing the adapter, why do not inherit
Adapter
, and inherit BaseAdapter
, because Adapter
it is an interface, and BaseAdapter
is inherited the interface of the abstract class, the implementation Adapter
of the partial method, so we on the basis BaseAdapter
of the time we only need to rewrite BaseAdapter
No implementation is possible, otherwise we directly inherit Adapter
to implement all the methods inside the interface.
The understanding of White Dragon Guardian + asynchronous message