android-Optimizing UI Performance (1)-reduces the blocking time of the main thread
one reduces the blocking time of the main thread
Android has provided a way to implement Asynctask to generate new asynchronous tasks from the main thread.
Define and implement the following classes (methods are automatically called by the system):
Public class downloadfilesasynctask extends asynctask<URL, Integer,Long>{ /* (non-javadoc) * Background execution function * @see android.os.asynctask#doinbackground (params[]) */@OverrideprotectedLong doinbackground (URL ... arg0) {//TODO auto-generated method stub return NULL; }//Execute after background thread finishes@Overrideprotected voidOnPostExecute (Long result) {//TODO auto-generated method stub}//execute before background thread starts@Overrideprotected voidOnPreExecute () {//TODO auto-generated method stub Super. OnPreExecute (); }//Set progress updates, such as setting a displayed progress bar@Overrideprotected voidOnprogressupdate (integer ... values) {//TODO auto-generated method stub}
By an asynchronous task, you can reduce the blocking time of the main thread
Copyright NOTICE: Welcome to communicate the error of the article, must be open-minded to answer, QQ872785786
Android-Optimizing UI Performance (1)-reduces the blocking time of the main thread