due to performance requirements, Android requirements can only be UI Update in Thread UI that you want to update in other threads UI , let us introduce a way: Use Asynctask Asynchronous Tasks .
in this way, the following updates a TextView :
Note: Updating the UI can only be done in the OnPostExecute (String result) method.
package com.example.runonuithreadtest; import android.app.activity; import android.os.asynctask; import android.os.bundle; import android.widget.textview; public class mainactivity extends activity { private textview tv; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.activity_main); tv = (TextView) findviewbyid (r.id.tv); new yibu (). Execute (); } class Yibu extends AsyncTask<String, String, String> { @Override protected string doinbackground (string... params) { try { thread.sleep (; } ) catch (interruptedexception e) { // TODO Auto-generated catch block e.printstacktrace (); } return null; } @Override protected void onpostexecute (String result) { // TODO Auto-generated method stub Tv.settext ("Updated TextView"); } } }
Yes , yes. APP performance test, I am more commonly used in this platform: www.ineice.com
How Android asynchronously updates the UI using the Asynctask asynchronous task