umar
umar

Reputation: 3133

Refreshing the activity

i am making the app in which user will be able to c the routine services available to him . For this i am using the website where the admin will be able to update the services . User from android will be able to get the list of services by parsing the xml file available on the server .

The thing i am wondering about is that is there any way the activity automatically refresh itself and user can c the updates done in the services by admin.

Thanks

Upvotes: 1

Views: 1099

Answers (1)

Malcolm
Malcolm

Reputation: 41510

If you need to do some job on a regular basis, you should have a look at the Handler and the AsyncTask. The general scheme is the following:

 //This handler launches the task
 private final Handler handler = new Handler();

 //This is a task which will be executed
 private class RefreshTask extends AsyncTask<String, Void, Object> {
     protected Object doInBackground(String... params) {
         //Do refreshing here
     }

     protected void onPostExecute(Object result) {
         //Update UI here
     }
 }

 //This is a Runnable, which will launch the task
 private final Runnable refreshRunnable = new Runnable() {
     public void run() {
         new RefreshTask(param1, param2).execute();
         handler.postDelayed(refreshRunnable, TIME_DELAY);
     }
 };

Then you call handler.post(refreshRunnable) when you want to start updates. To cancel them, call handler.removeCallbacks(refreshRunnable). I should note, of course, that I haven't tested this code, but it should give a general idea what to do.

Upvotes: 1

Related Questions