Package com. handlerThread; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. OS. handlerThread; import android. OS. logoff; import android. OS. message; public class handlerThread2 extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); // System. out. println ("activity Thread ID:" + Thread. currentThread (). getId (); HandlerThread handlerThread = new HandlerThread ("handlerThread"); handlerThread. start (); MyHandler handler = new MyHandler (handlerThread. getLooper (); Message msg = handler. obtainMessage (); // msg. arg1 = 123; // transmits Integer Data // msg. obj = "asd"; pass object type // use bundle object to pass value Bundle B = new Bundle (); B. putInt ("ID", 12); B. putString ("name", "thinkpad"); msg. setData (B); msg. sendToTarget ();} class MyHandler extends Handler {public MyHandler () {super ();} public MyHandler (Looper loler) {super (looper );} @ Overridepublic void handleMessage (Message msg) {super. handleMessage (msg); // int args = msg. arg1; // String s = (String) msg. obj; // get the bundle object Value Bundle B = msg. getData (); int id = B. getInt ("ID"); String name = B. getString ("name"); System. out. println ("id is" + id + ", name is" + name); // System. out. println ("handler Thread ID:" + Thread. currentThread (). getId ());}}}
Running result
So what is bundle? Let's take a look at the official explanation.