java - onPostExecute() invoked before doInBackground() method in the case of AsyncTask -


consider code below:

package com.reallybelievebig.asynctaskextracredit;  import android.os.asynctask; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.textview; import android.widget.toast;  public class asynctasktestactivity extends appcompatactivity {      private static final string tag = asynctasktestactivity.class.getsimplename();      protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_async_task_test);          new testtask().execute("execute");          log.d(tag, "in ui thread!");     }      private class testtask extends asynctask<string, integer, string> {          @override         protected string doinbackground(string... params) {             (int = 0; <= 100; i+=20) {                 try {                     thread.sleep(50);                 } catch (interruptedexception e) {                     log.e(tag, "exception caught: ", e);                 }                  publishprogress(i);             }              return "background task complete";         }          @override         protected void onprogressupdate(integer... values) {             toast.maketext(asynctasktestactivity.this, "progress: " + values[0], toast.length_long).show();         }          @override         protected void onpostexecute(string s) {             super.onpostexecute(s);             log.d(tag, "in onpostexecute: " + s);             toast.maketext(asynctasktestactivity.this, s, toast.length_long).show();         }     }  } 
  1. i starting asynchronous task main ui thread using testtask.execute() method.

  2. the doinbackground() method working fine. sleeps time, invokes publishprogress() method , displays toast in onprogressupdate() method.

  3. i expecting onpostexecute() method called after doinbackground() completed. start application, log message in onpostexecute() method.

there wrong not able figure out. issue in code?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -