什么是装载机上的AsyncTask在Android系统的优势在哪里? [英] What is the advantage of loaders over Asynctask in Android?

查看:222
本文介绍了什么是装载机上的AsyncTask在Android系统的优势在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有装载机在异步任务的任何优势?此外,如何使装载机兼容手机与Android Froyo的。

Are there any advantages of Loaders over Async task? Also, how to make loaders compatible for phones with Android froyo.

编辑:

这里的主要问题是,我不使用本机数据库(SqlLite)。使用开发服务器上的数据库。很显然,我不能使用 CursorLoader 了。 AsyncTaskLoader 有没有例子的。如果有,请做链接。

The primary problem here is that I'm not using the native DB(SqlLite). Using the DB on development server. Obviously, I can't use CursorLoader any more. AsyncTaskLoader has no examples at all. If any, please do link.

这是个更好的主意来加载需要到本地数据库中的数据,然后用它查询 CursorLoader

Is it a better idea to load the data required onto the local DB and then query it using CursorLoader?

推荐答案

是的,因为他们照顾了很多东西的AsyncTask达不到的,悲惨的装载机比AsyncTask的更有利。

Yes, Loaders are more advantageous than AsyncTask as they take care of a lot of things that AsyncTask falls short of, miserably.

  1. 屏幕方向的变化是很难在AsyncTask的。我曾经有过这样的问题,直到我用了一个活动控制类,这在我以前保留,同时配置改变。如果你想知道我可以给你一些code。该应用程序使用的崩溃,不过,当你连之前加载整个数据改变了方向倍数次。这里的秘密是不是你的第一个线程加载大量数据,并尽快完成你的线程任务。即使它发生在后台,Android有处理线程的一个破旧的方法。你永远不知道什么时候你的任务之一将被杀死。

  1. Screen Orientation changes are difficult in AsyncTask. I used to have such a problem, till I used an Activity Control class, which I used to retain while configuration changed. I can give you some code if you want to know how. The app used to crash, though, when you changed the orientation multiples times even before the entire data loaded. The secret here is not load a lot of data with your first thread and and finish your threading tasks as soon as possible. Even if it happens in the background, Android has a shabby way of dealing with threads. You never know when one of your tasks would be killed.

即使您使用AsyncTaskLoader,可以确保您使用的活动经理。这将帮助你获得更多的控制权的活性及AsyncTask的。

Even if you use a AsyncTaskLoader, makes sure that you use an Activity manager. This will help you in getting more control over the activites and AsyncTask.

是的,这是所有老版本的Andr​​oid兼容。您需要包括支持库(大部分的时间,这是包含在默认情况下,但它总是很高兴仔细检查。)

Yes, it is compatible in all the old version of Android. You need to include the support library(Most of the times, this is included by default but its always nice to double check.)

这篇关于什么是装载机上的AsyncTask在Android系统的优势在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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