- 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 message containing descriptions and arbitrary data objects for sending to handler
Its member variables are as follows:
Public Final class Implements parcelable { publicint , what ; Public int arg1; Public int arg2; Public Object obj; ... }
What is used to identify the message , or to let the recipient know what the message is about. Arg1 and arg2 are used to send values of some integer types. obj is used to transfer values of any type.
- Handler: The message processor, by overriding the Handler handlemessage() method, processes the different messages received in the method, for example:
Handler mhandler=New Handler () { @Override publicvoid Handlemessage (Message msg) { switch (msg.what) { testhandler.test:
+ = msg.arg1; LOG.D ("Progressvalue-------------->", progressvalue+ "");
Break
}
}
}
Elsewhere, a message is sent through the SendMessage () method for the Handlemessage () method to accept
classMyThreadImplementsRunnable { Public voidrun () { while(!Thread.CurrentThread (). isinterrupted ()) {Message Message=NewMessage (); Message.what=testhandler.test; Testhandler. This. Myhandler.sendmessage (message); Try{Thread.Sleep (100); } Catch(interruptedexception e) {thread.currentthread (). interrupt (); } } } }
The child threads process some time-consuming operations, and then sends the processed results through the SendMessage () method to the UI main thread. Let the handler of the main thread update the results of the UI component.
Introduction to the Android Bundle, handler, and message classes