排球或服务光标装载机光标、排球、装载机

2023-09-04 09:07:57 作者:她的糖好苦

我几乎总是使用服务时,我从Web服务下载数据。我把结果存储在数据库中,并使用游标装载机在我看来显示结果。但在谷歌发布网络库乱射我已经变得有点混乱。凌空库使用异步任务,而不是服务,它不使用游标。我想,我应该避免异步任务和存储我的数据在数据库中,这样我可以处理方向的变化适当地 - 而不会丢失数据并且具有需要重新下载数据。所以我的问题是,当我应该用我自己下载的策略排球呢?

I almost always use a Service when I download data from a web service. I store the result in a database and displays the result in my view using a cursor loader. But after Google released the network library Volley I have become a bit confused. The volley library uses async tasks instead of a Service and it doesn't use cursors. I thought that I was supposed to avoid async task and store my data in a database so that I could handle orientation changes properly - without loosing data and having the need to download the data again. So my question is, when should I use Volley instead of my own download strategy?

推荐答案

就个人而言,在过去,我使用的是服务,是很麻烦来实现发现,但在一天结束的时候是结构良好,是一个很好的一致的体验。但是,线程性能......很难管理。

Traditional Arch

Personally, in the past I've found using a service to be cumbersome to implement but at the end of the day was well structured and was a good consistent experience. But threading performance... hard to manage.

服务 查询 - >数据库负载 - >通知

Service query - > database load -> notify

UI 启动查询和光标负载 - >更新用户界面

UI initiate query and cursor load - > update ui.

使用凌空很容易让人跳过这是$ P $服务和数据库中pviously处理的整个组件。

With volley it is tempting to skip the entire component that was previously handled within a service and database.

UI 排球请求 - >排球响应 - >更新用户界面

UI Volley request -> Volley response -> update ui

不过,这种分崩离析相当迅速取决于你正在努力,以显示和数据甚至要查询反对任何下列条件之一的服务器

However, this falls apart quite quickly depending on the data you are trying to display and perhaps even the server you are querying against for any of the following requirements

正在显示的数据不是由同一个URL充分描述(例如,页)

用户可以滚动下来,拉更多的页面。然而,当用户回来的活动,甚至干脆转,呼叫凌空将返回一个结果只是初步的页面,除非你特别记住所有的页面由其他查询。这成为了很多工作的,是为了更方便的架构。甚至一个网页,略有不同,这可能是不一致的体验给用户,如果他们所做的一切是旋转手机。

The user might scroll down and pull in more pages. However when the user comes back to the activity or even simply rotates, the call to Volley will return a result for only the initial page unless you specifically remember all of the other queries that the page consists. This becomes a lot of work for an architecture that is meant to be more convenient. Or even a page that is slightly different, this can be an inconsistent experience to the user if all they did was rotate the phone.

的数据进行修改

它更容易在本地应用更改,然后应用到服务器时。由于只有凌空,你就必须做一个REST的更新和重新查询(所有previous查询)同步。

It's easier to apply the change locally and then apply to the server whenever. With volley only, you would have to do an REST update and requery (of all previous queries) synchronously.

在速度和持久性

排球是真快。但是,它缺乏除了缓存命中哪里有合适的,可以依赖要查询的服务器上的任何持久性。积极的缓存甚至会严重影响使用陈旧数据的应用程序。从本地数据库中提取,可能实际上是在过去的查询引用数据的多个活动,通过导航时提供了一致,快速的体验。纯凌空的经验可能需要您查询的数据,你在技术上已经由previous查询有,但没有中央数据存储来获得这些数据。

Volley is really fast. However, it lacks any persistence apart from cache hits where available which can depend on the server you are querying. Aggressive caching can even wreak havoc on your app with stale data. Pulling from a local database provides a consistent and fast experience when navigating through multiple activities that might actually be referencing data in past queries. A pure volley experience might require you to query for data you technically already have from previous queries but have no central data store to get that data from.

这些天我居然跳过了服务的一部分,但一切仍然从传统的弓

These days I actually skip the service part, but everything else remains from the traditional arch

UI 启动抽射查询和光标负载 - >更新用户界面

UI initiate volley query and cursor load - > update ui

排球查询 - >更新数据库 - >通知

Volley query -> update database -> notify

此外,还有什么能阻止你从具有UI平一个服务,然后该服务使用凌空......它看起来比较传统的有可能是价值将更多的控制逻辑的地方更集中,​​但事实上,它的运行从一个服务其实没有提供任何技术优势。

Also, there is nothing stopping you from having the ui ping a service and then the service uses volley... It will look more traditional there might be value moving more control logic to somewhere more centralised, but that fact that it's run from within a "service" actually offers no technical advantage.

我希望帮助。基本上,不要试图去只抽射,我想这将是一个非常具体的和简单的应用程序,如果这就是为你工作,希望我已经确定的主要隐患。

I hope that helps. Basically, don't attempt to go volley only, I tried and it would be a very specific and simple app if that's what worked for you and hopefully I've identified the main pitfalls.

另外,我发现robospice相同的陷阱,尽管它的服务是......但是......因人而异

Also, I found the same pitfalls with robospice despite it being in a service... But... YMMV