有一个Android应用程序同步REST服务 [英] Syncing a REST service with an android app

查看:240
本文介绍了有一个Android应用程序同步REST服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有,我用它来填充信息在我的数据库REST服务,也就是后来被我的应用程序。 我对此事的读取多个线程,现在已经决定我是怎么想的REST服务和我的数据库之间的同步工作。

There's a REST service that I use to populate info in my database, that is later used by my app. I've read several threads on the matter, and now have to decide how I want the sync between the REST service and my DB to work.

想想一个应用程序,获取信息的有关股票,并将其存储在一个数据库谷歌财经的API,显示当应用程序启动的信息,并发送通知当特定事件发生在股票价格中。

Think of an app that gets info from google finance APIs about stocks and stores it in a DB, displays the information when the app is launched, and sends notifications when specific events happen in the stock price.

我已经实现的AsyncTask的简单的选择,当用户手动请求同步时启动。现在,我要实现自动同步,这些都是我发现的选项:

I already implemented the simple option of AsyncTask that is launched when a user manually requests a sync. Now I have to implement the auto-sync and these are the options I found:

  • 创建一个服务,将做同步
  • 使用一个同步适配器/同步提供
  • Create a Service that will do the syncing
  • Use a Sync Adapter / Sync Provider

所以,我发现了很多的优势,第二个选择,特别是那些在这个的视频,而且还两个主要缺点:

So I found a lot of advantages to the second option, particularly those explained in this video, but also two major disadvantages:

  • 在我没有找到好的文档Android同步(一些第三方的文章,如<一个href="https://sites.google.com/site/andsamples/concept-of-syncadapter-androidcontentabstractthreadedsyncadapter">these,但谷歌官方或 Android开发指南)
  • 根据这篇文章搞乱了同步适配器可能会导致重大的问题,如操作系统崩溃并重启。
  • I couldn't find good documentation for android sync (a few third party articles such as these, but no official Google or Android Developers guide)
  • According to this article messing up in a Sync Adapter can cause major issues such as OS crash and reboot.

大多数我发现的信息是pretty的老,所以也许事情已经改变了,但我的应用程序应该与API 8级及以上的工作,所以我会非常感谢任何建议,并链接到有价值的文档。

Most of the info I found is pretty old, so maybe things have changed since, but my App is supposed to work with API level 8 and above, so I would be very thankful for any recommendations and links to valuable documentation.

推荐答案

与SyncAdapter一定要去。按照说明在这里:<一href="http://stackoverflow.com/questions/5253858/why-does-contentresolver-requestsync-not-trigger-a-sync/5255360#5255360">Why并ContentResolver.requestSync不会触发同步?。

Definitely go with SyncAdapter. Follow instructions here: Why does ContentResolver.requestSync not trigger a sync?.

要做到SyncAdapter,你也需要做一个帐户/ AccountAuthenticator一样,所以你SyncAdapter知道如何登录到您的服务 - 除非它真的是谷歌财经的API,在这种情况下,所有你需要做的是采用正确的权限清单,以便将已使用的帐户设置在手机上。

To do SyncAdapter, you'll also need to make an Account/AccountAuthenticator as well, so your SyncAdapter knows how to login to your service -- Unless it truly is the Google Finance APIs, in which case all you need to do is apply the right permissions in the manifest so that it will use the account settings already on the phone.

您没链接你提到讨论崩溃的文章,但我知道它,它实际上是在谈论账户 - 这是的,你确实需要小心

You didn't link the article you mentioned that discussed crashes, but I know it, and it's actually talking about Accounts -- Which yes, you do need to be careful with.

这篇关于有一个Android应用程序同步REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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