开发者

What is the right way to get updates from REST service by timer in Android? [closed]

It's difficult to tell what开发者_Go百科 is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I wonder what is the right way to get updates from REST service by timer in Android?

May be I should use timer task for this?

UPDATE: I need to receive updates even if user has switched to another application or receive a call. UI also should be updated. So when user switch back to the application he should see updated view.


Here is an example that might help:

Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask(){ public void run()
        {onTimerTick();}}, 0, 1000L);

private onTimerTick_()
{
 // do REST call

}

You will want to make sure this is in a seperate thread.


'The right' way depends on what you are trying to do. Update your GUI? Update a datastore in the background while the app is not visible? AlarmManager lets you fire off a service to get data even if your app is not currently running, unlike TimerTask, so it's better for the second case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜