开发者

Refreshing the activity

开发者 https://www.devze.com 2023-03-01 03:55 出处:网络
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 service开发者_如何转开发s . User

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 service开发者_如何转开发s . 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消