开发者

setInterval equivalent in Android/Java?

开发者 https://www.devze.com 2023-03-30 17:30 出处:网络
I want to be able to run a service that checks with a remote server at predefined intervals. How would I go about doing such a thing in Android? Example开发者_如何学C: The user sets an option that the

I want to be able to run a service that checks with a remote server at predefined intervals. How would I go about doing such a thing in Android? Example开发者_如何学C: The user sets an option that they want to check for updates every 10 minutes, how would I do this?


you can use the handler for that, like

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);
    }
}

you can set the user define time in postDelayed() method

here are the link

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

0

精彩评论

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