Well, this is a very strange problem that I am facing, and I am sure that I am confused somewhere, but I can not understand where.
What I'm trying is
- Schedule a
Timer to execute a TimerTask every five seconds TimerTask in turn executes AsyncTask (which in this case simply falls asleep for a second before returning a static amount of AsyncTasks number).- Finally, the above account is updated in the user interface.
And, of course, the corresponding Handler and Runnable were used to host asynchronous messages from other threads to the user interface.
This code is executed only once. I expect him to fire every 5 seconds. Here is the code.
Note: I had no idea what to do with Looper . I put it there after trial and error!
public class TimerAsyncMixActivity extends Activity { public static final String TAG = "TimerAsyncMix"; static int executionCount = 0; Handler mHandler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new Timer().schedule(new MyTimerTask(this), 0, 5000); } class MyAsyncTask extends AsyncTask<String, Void, Integer>{ @Override protected Integer doInBackground(String... params) { try { Thread.sleep(1000); } catch (InterruptedException e) {
Can someone point me to what I am doing wrong?
android handler android-asynctask looper timertask
curioustechizen
source share