Android : Errors making async http request in timer thread

on Sunday, August 10, 2014


I'd like to send http requests every N seconds. The response should be shown is some textViews.


I got error that "Can't create handler inside thread that has not called Looper.prepare()"


My code is below:



private void runTimer() {
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
myTimer.schedule(myTask, 3000, 1500);

}
class MyTimerTask extends TimerTask {
public void run() {
asyncGetRequest();
}
}



private void asyncGetRequest(){
new DownloadWebPageTask().execute("http://www.google.com");
}

....

//this method is called automatically after receiving http response
@Override
protected void onPostExecute(String result) {
someTextView.setText("some text");
}


Thanks!!!


0 comments:

Post a Comment