我希望能够运行以预定义的间隔检查远程服务器的服务.我如何在Android中做这样的事情?示例:用户设置他们想要每10分钟检查一次更新的选项,我该怎么做?
Pra*_*tik 14
你可以使用处理程序,比如
Handler handler = new Handler();
private Runnable updateData = new Runnable(){
public void run(){
//call the service here
////// set the interval time here
handler.postDelayed(updateData,10000);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在postDelayed()方法中设置用户定义时间
这是链接
http://developer.android.com/reference/android/os/Handler.html
http://www.vogella.de/articles/AndroidPerformance/article.html
http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html
http://www.satyakomatineni.com/akc/display?url=DisplayNoteIMPURL&reportId=3496
http://www.helloandroid.com/taxonomy/term/43
| 归档时间: |
|
| 查看次数: |
10145 次 |
| 最近记录: |