谷歌IO其余的设计模式,完成ContentProvider的,现在卡 [英] Google IO Rest design pattern, Finished ContentProvider and stuck now

查看:208
本文介绍了谷歌IO其余的设计模式,完成ContentProvider的,现在卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,看后非常知道视频上这个话题我决定去与设计模式B.使用ContentProvider的与servicehelper。

So after watching the very know video on this topic i decided to go with design pattern B. Using a contentprovider with servicehelper.

Basicly我有以下文件:

Basicly i have the following files:

  • MYPROVIDER
  • MyDatabase的
  • Mycontract

在活动现在我可以得到ContentResolver的并查询供应商。所有的是伟大的工作至今。

in the activity i can now get the contentresolver and query the provider. All is working great so far.

现在我需要同步我的ContentProvider从我的REST API获取数据。 因此我需要实现一个服务辅助服务和休息方法。 研究谷歌的IO应用程序帮助我很多,即时通讯新手与Android所以它仍然很难搞清楚。

Now i need to sync my contentprovider to fetch data from my REST API. Thus i need to implement a service helper service and Rest method. Studying the Google IO app has helped me alot, im novice with android so it's still hard to figure it out.

我看到谷歌使用RemoteHandlers处理外部数据,我猜他们是图中的处理器类?

I see Google uses RemoteHandlers to process the external data, i guess they are the Processor classes in the diagram?

我不明白什么是我怎么能实现servicehelper +服务的一部分从网络获取数据。

What i dont understand is how i can implement the servicehelper + service part to get the data from the network.

  • 我在哪里可以调用该服务帮助?
  • 什么是服务和帮助需要做的是什么呢?
  • 有没有这个确切的设计模式的任何好的例子?

我看了几个主题堆栈这一点,所有的提示不同的方法。我发现一个例子至极声明一个restprovider然后MYPROVIDER有延长的供应商。我不喜欢这些解决方案,并要遵循这一结构化的设计模式。 IM希望你们能帮助我了!

I have read several topics on stack about this, all suggesting different methods. I found an example wich declares a restprovider and then myProvider has to extend that provider. I dont like those solutions and want to follow this structured design pattern. Im hoping you guys can help me out!

编辑:项目源可用: https://github.com/samvdb/TracknTrace

推荐答案

在我的理解模式是:

  • 请不要显示一个空的活动,并在背景中加载的内容。当加载失败,无法显示任何内容。
  • 而不是通过显示内容提供商和适配器存储在数据库中存取数据 - 这保证了用户总能看到内容
  • 在后台获取新的数据,一旦数据是手机的活性是通过适配器自动更新

要您的问题(我改的顺序):

To your questions (I changed the order):

我从哪儿调用服务的帮手?
我选择守夜通话模式的。在这种情况下,呼叫取决于你的应用。你可以触发更新应用程序启动时,在创建活动或当用户选择更新按钮时。我会选择在活动创作。

您已经选择的模式B.在这种情况下,很显然,内容提供商必须触发更新。什么时候?为了获得新的数据:在创建时或之后的第一个读访问。我会使用创建时间。对于创建,更新,在您的内容提供相应的动作后删除。

是否有这个确切的设计模式的任何好的例子?
从我的岗位在 http://stackoverflow.com/a/8693919/734687 :唯一的开源参考实现,我知道正在 http://datadroid.foxykeep.com 可用。这是一个库,你可以在自己的应用程序中使用。该架构下/ presentation解释 - 确保你读它

什么是服务,帮助需要做的是什么呢?
如果你看一下href="http://dl.google.com/googleio/2010/android-developing-RESTful-android-apps.pdf">幻灯片在幻灯片19

Where do i call on the service helper?
I choose pattern A from Vigils talk. In that case the call depends on your application. You could trigger the update when the application starts, when the activity is created or when the user selects an update button. I would choose at activity creation.

You have choosen pattern B. In that case it is clear that the content provider has to trigger the update. When? For getting new data: at creation time or after the first read access. I would use the creation time. For create, update, delete after the corresponding action in your content provider.

Are there any good examples of this exact design pattern?
From my post at http://stackoverflow.com/a/8693919/734687: the only open source reference implementation I know is available under http://datadroid.foxykeep.com. It is a library which you can use in your own application. The architecture is explained under /presentation - make sure you read it.

what does the service helper need to do exactly?
If you look at the slides at slide 19 it is a singleton which encapsulates the call to the service and handles the asynchronous calls via request ids.

什么是服务需要做什么呢?
该服务(在presentation幻灯片17),只是保证在后台执行的操作。

what does the service need to do exactly?
The service (slide 17 in the presentation) just ensures that the action is performed in the background.

这篇关于谷歌IO其余的设计模式,完成ContentProvider的,现在卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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