Bundles are a carrier that can store basic data types, objects, and so on, which is equivalent to a car that can load a lot of things and then transport it to where it's needed, such as:
Bundle mbundle=New bundle (); Mbundle.putstring ("name", "Zhaolinit"); Mbundle.putint (" Number ", 123456); Mbundle.putboolean (" flag ",false); // then, put it in the intent object Intent mintent=New Intent (); Mintent.putextras (mbundle);
M essage: A messag
The code is as follows:1 PackageCom.wyl.handler_mars;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 ImportAndroid.os.Handler;6 ImportAndroid.os.Looper;7 ImportAndroid.os.Message;8 ImportAndroid.util.Log;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One ImportAndroid.widget.Button; A ImportAndroid.widget.TextView; - ImportAndroid.widget.Toast; - /** the * The main thread sends the message, the worker thread receive
1. when a handler creates an instance, it is associated with a logoff object, which is a member of its corresponding thread variable copy-threadlocal variable. When it sendmessage, the message. set the handler object of the taget and add it to the messagequeue Of The logoff, waiting for the message loop.
2. logoff m
Android only allows the UI thread to modify the UI components in the activity. When the Android program starts for the first time, Android initiates a primary thread (main thread), which is primarily responsible for handling UI-related events, such as user keystroke events, screen drawing events, and distributing related events to the corresponding component for processing. SoThe main thread is also often referred to as the UI thread。 Android only allows the UI thread to modify the UI component
First look at an Android system startup flowchart:One of the two most important indicators of a process is the initiation of the binder thread pool, which is the ability to process binder interprocess communication. Another is the launch of the handler message loop, which enables the use of the message loop mechanism.1. When did the Systemserver process implement
To do a simple little demo about Handler,looper,message, a button on the main interface of the code, click Send Message (accumulate) to the thread's Looper loop, and then print it out in Logcat:Package Zhangphil.looper;import Android.os.bundle;import Android.os.handler;import android.os.looper;import Android.os.message;import Android.util.log;import Android.view.
Problem Description:The Handler inner class holds a reference to the external class activity, and if the activity exits and the message that Handler has deferred processing is not processed, the activity will not be recycled, which can cause memory leaks repeatedly.Solution: 1, OnDestroy when the message is purged.M
Handler. sendmessage (new message). This method means that handler needs to send a new object when sending a message. That is, after updating the date when sending a message, you need to reconstruct the message object instead of u
The message usage of Android is usually logoff. prepare () logoff. myLooper (); xxxHandler = new Handler () {handleMessage (Message msg ){...}}; logoff. loop (); At the beginning, I was confused about the situation. Based on the name, I couldn't see the two classes that have any relationships. How do I transmit messages? It's okay to know how to use it. Many peop
Android applications are driven by messages , and the system maintains a message team example (Mesagequeue)for each application, and the main thread of the application constantly gets messages from this message team example (Mesage), These messages are then processed (Handler), which enables the execution of the application to be driven by messages.When Activitym
Updating the UI with handler1 PackageActivity.cyq.handlermessage;2 3 Importandroid.content.res.Resources;4 ImportAndroid.graphics.Bitmap;5 Importandroid.graphics.BitmapFactory;6 ImportAndroid.os.Handler;7 ImportAndroid.os.Message;8 Importandroid.support.v7.app.AppCompatActivity;9 ImportAndroid.os.Bundle;Ten ImportAndroid.widget.Button; One ImportAndroid.widget.ImageView; A ImportAndroid.widget.TextView; - ImportAndroid.widget.Toast; - the - Public classMainactivityextendsappcompatactivity {
To add a message to a window WM_ERASEBKGND the handler function
VC6.0
1,
A. First, to add the OnEraseBkgnd function (WM_ERASEBKGND) for the convenience of using the erase background below
Press the shortcut key Ctrl+w Open ClassWizard dialog box (or menu->view->classwizard): Select Class Info, find the lower left corner of the MessageFilter, Drop-down list to the bottom, select window, OK save;
B. Let's ctr
Han Mengfei sha Han Yafei [email protected] yue31313 Han_meng_fei_shaThe Circulator Looper manages the exchange of messages between objects within the thread MessageexchangeCirculator manages Message Queuing for this line threadThe processor communicates with the Circulator, pushing a new message to the message queue or receiving a
Note: Data returned from the server should be processed in handlemessage. Otherwise, the results will not be obtained due to thread issues.
Public class mainactivity extends activity {private string responseinfo; private handler; @ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); handler = new
The example of this article describes the development of Android programming Seekbar using handler message processing operations. Share to everyone for your reference, specific as follows:
This case simple implementation progress bar can go, can drag and drop function, below see source code:
Layout file:
Java files:
Package Com.example.lession16_seekbar;
Import Android.os.Bundle;
Import
the post source code:See Handler.java first. Public Final Boolean Post (Runnable r) { return sendmessagedelayed (Getpostmessage (R), 0); } Private Final Message Getpostmessage (Runnable r) { = message.obtain (); = R; return m; }See Message.obtain again () Public intwhat ; Public StaticMessage obtain () {synchronized(spoolsync) {if(SPool! =NULL) {Message m=SP
Hander and message1.handeraction: Accepts data from a child thread (message or Runable object) to update the bound object. Why it appears: There are some time-consuming actions in Android or other applications, and if they all appear in the main thread, you can't do anything else when they do. Then people think, can you apply for some "resources", Designed to handle this time-consuming operation without affecting the current process.so multithread
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.