正确使用onUpgrade(和内容提供商)来处理更新,而不会阻塞主线程,是`Loader`s毫无意义? [英] Correctly using onUpgrade (and content providers) to handle updates without blocking the main thread, are `Loader`s pointless?

查看:262
本文介绍了正确使用onUpgrade(和内容提供商)来处理更新,而不会阻塞主线程,是`Loader`s毫无意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是的,涉及穿越我称之为的Hello World海湾我在世界,你好我可以使用SQLite和内容提供商(和解析器),但我现在需要跨越其他的问题之一一边,我不能作一个假设,onUpgrade将快速。

This is one of the questions that involves crossing what I call the "Hello World Gulf" I'm on the "Hello world" I can use SQLite and Content Providers (and resolvers) but I now need to cross to the other side, I cannot make the assumption that onUpgrade will be quick.

现在我去到预定(Wrox的,专业的Andr​​oid 4.0的发展 - 我没有选择了它,因为专业,所以我选择了它,因为Wrox的就像导游的奥赖利 - 奥赖利吮吸导游,他们是参考书)只涉及简单地使用装载机 S,所以我做了一些搜索,多一些阅读等等。

Now my go-to book (Wrox, Professional Android 4 development - I didn't chose it because of professional, I chose it because Wrox are like the O'Reilly of guides - O'Reilly suck at guides, they are reference book) only touches briefly on using Loaders, so I've done some searching, some more reading and so forth.

我已经基本结束一个装载机比包装更小,它只是做在不同的线程的事情,并给你的回调(在该工作线程)处理的东西,它给你的3个步骤,发起查询,使用查询的结果,和重置该查询。

I've basically concluded a Loader is little more than a wrapper, it just does things on a different thread, and gives you a callback (on that worker thread) to process things in, it gives you 3 steps, initiating the query, using the results of the query, and resetting the query.

这似乎是一个相当薄的包装,所以问题1:

This seems like quite a thin wrapper, so question 1:

我为什么要使用装载机 S'

Why would I want to use Loaders?

我意识到我可能会丢失你看到的东西,最实用工具像这样与Android是真正有用的,如果你用粮这么说走了,正如我所说的装载机看起来像一个pretty薄包装,和他们强迫我有回调的名称有多个查询正在进行这有可能成为繁琐

I sense I may be missing something you see, most "utilities" like this with Android are really useful if you go with the grain so to speak, and as I said Loaders seem like a pretty thin wrapper, and they force me to have callback names which could become tedious of there are multiple queries going on

http://developer.android.com/reference/android/content/ Loader.html

读取指出,他们应该在监测变化的数据和行为 - 这听起来不错,但如何,实际上是做了不是很明显(我想数据库表虽然)

Reading that points out that "they ought to monitor the data and act upon changes" - this sounds great but it isn't obvious how that is actually done (I am thinking about database tables though)

presentation

应如何改变我的应用程序的外观?我应该把装载纺纱的事情(我不知道的名字,从来不需要他们之前)一定的时间后创建活动后?因此,片段是空白,但是如果X没有时间装载机经过汇报,我将展示一个带刺的东西吗?

How should this alter the look of my application? Should I put a loading spinning thing (I'm not sure on the name, never needed them before) after a certain amount of time post activity creation? So the fragment is blank, but if X time elapses without the loader reporting back, I show a spiny thing?

其他操作

装载机是更新和明确等无用的,他们的名字单独讲述了一个这么多,所以任何讨厌的更新,这样就必须由我自己的系统进行调车作业的一名工人线程包裹。这进一步导致了我想知道我为什么要装载机?

Loaders are clearly useless for updates and such, their name alone tells one this much, so any nasty updates and such would have to be wrapped by my own system for shunting work to a worker thread. This further leads me to wonder why would I want loaders?

我觉得我的回答是
某种包装的(在一定程度上,内容提供商或其他方式)做一个工作线程的东西将意味着升级发生在该线程,因为......好吧,这不是主线程这解决了问题。

What I think my answer is Some sort of wrapper (at some level, content provider or otherwise) to do stuff on a worker thread will mean that the upgrade takes place on that thread, this solves the problem because ... well that's not on the main thread.

如果我不写我自己,我可以再(如果我想)确保查询按照一定的顺序发生的,用我自己的数据结构(而不​​是捆绑取值)看来我有更好的控制。

If I do write my own I can then (if I want to) ensure queries happen in a certain order, use my own data-structures (rather than Bundles) it seems that I have better control.

我真的很想找

讨论,我觉得当一个人知道为什么事情的方式,他们是人让更少的错误,只是一般拥有更多的信心,我肯定是有原因的装载机取值存在,而且会有一些模式,所有的Andr​​oid借自己对,我想知道这是为什么。

Discussion, I find when one knows why things are the way they are that one makes less mistakes and just generally has more confidence, I am sure there's a reason Loaders exist, and there will be some pattern that all of Android lends itself towards, I want to know why this is.

例如:

适配器(用于列表视图),它不会立即明显的一个如何跟踪行(插入)为什么必须指定一个默认样式(为什么ArrayAdapter使用的toString)当大多数的时间(以我的经验,我敢说)它是子类,阅读源$ C ​​$ C给人一种什么样的适配器必须实际做的话,我挑战自己:我能想到的(更好)系统,该系统满足这些要求的的理解,通常是(希望)我的回答该收敛于它是如何实际进行。

Adapters (for ListViews) it's not immediately obvious how one keeps track of rows (insert) why one must specify a default style (and why ArrayAdapter uses toString) when most of the time (in my experience, dare I say) it is subclasses, reading the source code gives one an understanding of what the Adapter must actually do, then I challenge myself "Can I think of a (better) system that meets these requirements", usually (and hopefully) my answer to that converges on how it's actually done.

因此​​,的Hello World湾的跨越。

Thus the "Hello World Gulf" is crossed.

我期待着就此事阅读答案和任何链接的文本墙壁。

I look forward to reading answers and any linked text-walls on the matter.

推荐答案

你不应该直接使用装载机,而是LoaderManager

you shouldnt use Loaders directly, but rather LoaderManager

这篇关于正确使用onUpgrade(和内容提供商)来处理更新,而不会阻塞主线程,是`Loader`s毫无意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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