The understanding of White Dragon Guardian + asynchronous message

Source: Internet
Author: User

The understanding of White Dragon Guardian + asynchronous message

手机卫士MobileSafe

Mobilesafe 1.0
    1. Splash interface (set a gradient animation)
    2. 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
    1. Note that each time you write the code, notice whether the fragment isnull
    2. 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

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.