Android的SyncAdapter用例 [英] Android SyncAdapter use case

查看:250
本文介绍了Android的SyncAdapter用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在做的现在?
我们有一些结构化的,文字的服务器上使用Web服务(REST风格)暴露数据。我的应用程序调查此服务器定期(AlarmManagerService)获取数据,并将其保存在本地数据库(源码)。另外,用户的身份验证和授权事先进行访问。

问题:

  1. 有一个在SDK中SyncAdapter /的AccountManager类的,我想知道是否可以在我的应用程序的任何使用,以实现上述同步?

  2. 如果有,是什么样的基础设施,需要在后端支持同步设置使用此适配器?链接,让使用该适配器和其他信息的详细信息的文章等是AP preciated。

解决方案

是SyncAdapter /的AccountManager是你的用例是有用的。该验证器(它调用的AccountManager幕后)可以处理身份验证的应用程序。该SyncAdapter可以从服务器到本地数据存储处理周期同步。你不会有使用AlarmManager自己去实现它。有关使用SampleSycnAdapter /验证程序请参阅<样品code href="http://developer.android.com/resources/samples/SampleSyncAdapter/index.html">SampleSyncAdapter在机器人devguide。

您后端REST服务器将与SyncAdapter就好了工作,没有太大的变化。唯一的区别将是你的客户,例如像,而不是调用服务器获取数据的方法在AlarmManager,你会改为调用你的类延伸SyncAdapter的他们onPerformSync()。上述样品code将使更多clear.Hope这会有所帮助。

What we are doing currently?
We have some structured, textual data on a server which is exposed using web services(RESTful). My application polls this server regularly(AlarmManagerService) to fetch the data and save it on local database(sqlite). Also, a user is authenticated and authorized beforehand for access.

Questions:

  1. There is a SyncAdapter/AccountManager class in the SDK and I was wondering if it can be of any use in my application to achieve the syncing mentioned above?

  2. If yes, what sort of infrastructure is needed at back end to support a sync set up using this adapter? Links to articles etc. that give details of using this adapter and other info is appreciated.

解决方案

Yes SyncAdapter/AccountManager is useful for your usecase. The Authenticator ( which calls AccountManager behind the scene) can handle authentication for your app. The SyncAdapter can handle periodic syncs from server to local datastore. You wont have to implement it yourself using AlarmManager. For samplecode on using SampleSycnAdapter/Authenticator please see the SampleSyncAdapter in android devguide.

Your backend REST server will work with the SyncAdapter just fine, without much changes. The only differences would be in your client, like for example instead of calling server's fetch data methods in AlarmManager, you would instead call them in onPerformSync() of your class which extends SyncAdapter. The sample code mentioned above will make it more clear.Hope this helps.

这篇关于Android的SyncAdapter用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆