Read about android os handler handlecallback, The latest news, videos, and discussion topics about android os handler handlecallback from alibabacloud.com
rewriting.
2) final boolean hasMessages (intwhat): checks whether the queue contains messages with the value of what.
3) final boolean hasMessages (intwhat, Object object): checks whether the queue contains messages with the "what" attribute as the specified value and the "object" attribute as the specified Object.
4) Multiple overloaded Message obtainMessage (): gets the Message. SendEmptyMessage (int what): sends an empty message.
5) final booleansendEmptyMessageDelayed (int what, long delayM
); } Values.put (this, value); }From the above code can be learned that each thread can hold at most one Looper object, note that the emphasis here is that each thread can only hold one copy, not sthreadlocal can only put one, which is also the thread localization store 's Secret. So we get a pre-condition in call like new Handler () {}; Statement, the looper.prepare () must have been executed beforehand; statement, and make sure that a
Next, let me introduce how to use Android Handler. Handler can send Messsage and Runnable objects to the Message Queue of the associated thread. Each Handler object is associated with the thread that created it, and each Handler object can only be associated with one thread.
Handler is primarily the main thread and sub-threading communication. In general, some time-consuming operations in a child thread are done to notify the main thread to modify the UI.In fact, the Android system in activity startup or state changes are implemented through the handler mechanism.First, enter into the main method of Activitythreadpublic static void M
); Timer.schedule (task, 10000); } }Method Five: (Runnable + handler.postdelayed (runnable,time))Regularly update the UI on Android, usually using java.util.Timer, java.util.TimerTask, Android. Os. Handler combination. In fact, handler itself has provided a timed funct
Windows programmers may know that Windows programs are message-driven and have a global message loop system. Android applications are message-driven, and the message loop mechanism should also be provided. Android uses logoff and Handler to implement the message loop mechanism. Android message loops are targeted at thr
When an APK application is started, Android starts a main thread (ui thread). Because the main thread is non-thread safe, when we need to operate these time-consuming operations such as big data or networking in the main thread, the display of the android UI will be affected and the status will be suspended, this is not optimistic about the user experience. Therefore, we need to hand over the time-consuming
Hello everyone, this section is about the use of Android handler. before talking about handler, let's raise a small question: how can the program update the title in five seconds.
First, let's take a look at the Java programmers who are used to writing programs before they know how to use handler. The Code is as follow
scans all the folders containing images on the mobile phone, and finally selects the most picture folder, and displays the images in the folder using the GridView.1. layout File
The layout file is quite simple, just like a GridView
2. MainActivity
Package com. example. zhy_handler_imageloader; import java. io. file; import java. io. filenameFilter; import java. util. arrays; import java. util. hashSet; import java. util. list; import an
message on the UI.
Why is the handleMessage method automatically called when a handler object is initialized? The reason is that there is a loose object in the android. OS. Handler class, which cyclically retrieves messages from the message queue and calls handleM, but returns a method.How does
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.