Google IO Rest design pattern, finished ContentProvider and stuck on getting the data from the network

社会主义新天地 提交于 2019-12-02 15:44:26
ChrLipp

In my understanding the pattern is:

  • Don't show an empty activity and load the content in the background. When the loading fails you cannot display anything.
  • Instead display data stored in the db accessible via a content provider and an adapter - this guarantees that the user always see a content
  • In the background fetch new data, once the data is on the phone the activity is automatically updated through the adapter

To your questions (I changed the order):

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 https://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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!