What to use when loop inside a background thread and keep updating UI?

443 Views Asked by At

I'm design an app that keep sending JSON data to a server after t seconds and updating web view whenever it get an response from that server (after sending success). I want this background job running forever until i quit the app. Should i use loop inside an async task ?

I read in android main page that Async Task should be use as a one-time only job.

1

There are 1 best solutions below

0
Saurav Kumar On

Use Runnable and Handler Class to execute a function with post delayed

    Handler handler = new Handler();
    final int delay = 5000; //milliseconds

    Runnable r=new Runnable(){
        public void run(){
          //Execute your asynctask here 
        }
    };
    handler.postDelayed(r, delay);

And update the UI in onPostExecute of Asynctask