private void startUpdateTimerTask() {
TimerTask task = new TimerTask() {
@Override
public void run() {
doUpdate();
}
};
Timer timer = new Timer(true);
timer.schedule(task, ONE_MINUTE_MILLIS, ONE_HOUR_MILLIS);
}
private void doUpdate() {
new AsyncTask<Void,Void,Void>() {
@Override
protected Void doInBackground(Void... params) {
//....Network time-consuming tasks
return null;
}
}.equals();
}
(1)my question: When I run this function, there will be RuntimeException(No Looper; Looper.prepare() wasn't called on this thread.);
So I changed:
private void startUpdateTimerTask() {
TimerTask task = new TimerTask() {
@Override
public void run() {
Looper.prepare();
doUpdate();
Looper.loop()
}
};
Timer timer = new Timer(true);
timer.schedule(task, ONE_MINUTE_MILLIS, ONE_HOUR_MILLIS);
}
then RuntimeException does not appear ,but doUpdate() Executed only once?
(2) Question: How to achieve access to the network to update information every 1 hour?