Activity Update

I am making an application in which the user will be able to use the usual services available to him. To do this, I use a website where the administrator can update the services. A user from android will be able to get a list of services by analyzing the xml file available on the server.

The thing that I'm interested in is that some way automatically updates activity, and the user can with updates performed by the administrator in the services.

thank

+1
android
Apr 28 2018-11-21T00:
source share
1 answer

If you need to do some work on a regular basis, you should take a look at Handler and AsyncTask . The general scheme is as follows:

//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 the update. To undo them, call handler.removeCallbacks(refreshRunnable) . I should note, of course, that I have not tested this code, but it should give a general idea of ​​what to do.

+1
Apr 28 '11 at 17:09
source share



All Articles