Public class handlethreadtestactivity extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); handlerthread myhandlethread = new handlerthread ("my_handler1"); // 1. create a handlerthread thread object my_handler which is the name of this thread object myhandlethread. start (); // 2. start thread myhandle = new myhandle (myhandlethread. getlooper (); // 4. bound to the created thread message MSG = myhandle. obtainmessage (); // 5. get the MSG object bundle B = new bundle (); B. putint ("Age", 12); B. putstring ("name", "super_cj"); MSG. setdata (B); // bind the data MSG to the MSG object. sendtotarget (); // send MSG to the bound thread} class myhandle extends handler // 3. create a handler internal class {public myhandle () {} public myhandle (low.low.low.) // reload myhandle to allow the parent class handler to add myhandlerthread to the thread queue {super (low.n );} @ overridepublic void handlemessage (Message MSG) {// The code you want to asynchronously process in the thread // todo auto-generated method stubsuper. handlemessage (MSG); bundle BB = MSG. getdata (); // get the data int age = BB passed by MSG. getint ("Age"); string name = BB. getstring ("name"); toast. maketext (handlethreadtestactivity. this, String. valueof (AGE), toast. length_long ). show (); try {thread. sleep (5000); // pause the thread for 5 seconds toast. maketext (handlethreadtestactivity. this, name, toast. length_long ). show () ;}catch (exception e ){}}}}
I am also a beginner. When I forget it, let's take a look at what's wrong. Please help me to point it out. Thank you!