0

I need to start background task. Task call async http request and if condition is valid show alert.

I implemented it but I receive this error:

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

This is my java code:

    Timer timer = new Timer();
    timer.schedule(new RequestScheduledTask(), intervalTask);

    class RequestScheduledTask extends TimerTask {
    @Override
    public void run() {
            myCall();
    }
}

Can you help me please?

Thanks

Luca

Langusten Gustel
  • 10,917
  • 9
  • 46
  • 59
Luca Santaniello
  • 161
  • 1
  • 11

2 Answers2

0

According to the following post you are doing something in a thread that is meant to be called on the main thread! What is myCall(); doing?

And don't do http request with async tasks thats bad practice.

I would recomment to use volley:

[edit]

Okay its the loading indicator that is should be called on the main thread. I guess you are doing it in the AsyncTask. You can use Activity.runOnUiThread(Runnable()) to run a runnable to display it.

Community
  • 1
  • 1
Langusten Gustel
  • 10,917
  • 9
  • 46
  • 59
0

for example I need refresh adapter list when data is changed. Data returned from webserver could to be changed or not. if it is changed I must refresh listview/adapter, else nothing.

myCall call server, get data response (using other framwork like volley) and then update list view.

When myCall start I want display loading indicator but when I show it, app crash with runtime exception

  java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Luca Santaniello
  • 161
  • 1
  • 11