刷新活动 [英] Refreshing the activity
问题描述
我正在使该应用在其中用户将能够到c提供给他的常规服务。为了这个,我现在用的是网站,管理员就能够更新服务。用户从Android将能够通过解析服务器上可用的XML文件,以获得服务列表。
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 .
我想知道的是,事情有没有什么办法的活动自动刷新自身和用户可c。通过管理员的服务做了更新。
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.
感谢
推荐答案
如果你需要做定期一些工作,你应该有一个看的处理器和的 AsyncTask的。总体方案如下:
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);
}
};
然后调用 handler.post(refreshRunnable)当你要开始更新
。要取消他们,叫 handler.removeCallbacks(refreshRunnable)
。我要指出,当然,我没有测试此code,但它应该给一个总体思路做什么。
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.
这篇关于刷新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!