问题
How can an AsyncTask be started after a 3 second delay?
回答1:
You can use Handler for that. Use postDelayed(Runnable, long) for that.
Handler#postDelayed(Runnable, Long)
回答2:
Using handlers as suggested in the other answers, the actual code is:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new MyAsyncTask().execute();
}
}, 3000);
回答3:
You can use this piece of code to run after a 3 sec delay.
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// run AsyncTask here.
}
}, 3000);
回答4:
Use Handler class, and define Runnable handleMyAsyncTask
that will contain code executed after 3000 msec delay:
mHandler.postDelayed(handleMyAsyncTask, 1000*3);
来源:https://stackoverflow.com/questions/4177409/java-android-how-to-start-an-asynctask-after-3-seconds-of-delay