The Android sub-thread cannot update the UI has been deeply rooted in my mind, it was taken for granted that the child thread is also not allowed to interface jump, but in the later study, found that it is possible to go through the child thread to the activity of the jump, Immediately shocked me. Get the hell out of the code and test it out. The results really can be. I want to make a note.
Activity
Package Com.example.testchildthreadgootheractivity;import Android.app.activity;import Android.content.Context; Import Android.content.intent;import android.os.bundle;import Android.util.log;import Android.view.Menu;import Android.view.menuitem;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public class Mainactivity extends Activity {private Context context; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); context = this;//the first button, jumps the activity through the main thread, and passes the content Findviewbyid (R.ID.BTN_GO1). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {log.e ("test", "Main thread:" + Thread.CurrentThread (). GetName () + "ID:" + thread.currentthread (). GetId ()); Intent Intent = new Intent (context, Otheractivity.class);//test pass string Intent.putextra ("Hello", "Hello im main thread"); StartActivity (intent);}); /second button, jump activity through a child thread, and pass content FIndviewbyid (R.id.btn_go2). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {New Thread ( New Runnable () {@Overridepublic void run () {LOG.E ("test", "Child Thread:" + thread.currentthread (). GetName () + "ID:" + thre Ad.currentthread (). GetId ()) Intent Intent = new Intent (context, otheractivity.class);//test pass string Intent.putextra (" Hello "," Hello im Child thread "); StartActivity (intent);}}). Start ();}});}}
The test concludes. Child threads can jump to activity. and passing content through intent
Android jumps to activity and delivers content through a child thread