[英]Android loaders vs Handlers
The loaders
help in asynchronously getting the data from a data source. loaders
帮助异步获取数据源中的数据。 We can achieve the same effect using Handlers
, where we can kick off a thread or execute a Executor and can fetch the data in that thread. 我们可以使用
Handlers
实现相同的效果,我们可以启动线程或执行Executor并可以获取该线程中的数据。 Once data is fetched, we can update the UI using the UI handler Message mechanism. 获取数据后,我们可以使用UI处理程序Message机制更新UI。 Then why do go for coding the complex loaders when we can achieve the same by using
Handlers
. 那么为什么我们可以通过使用
Handlers
来实现相同的复杂加载器编码。
Loaders were introduced to make it easier in implementing correct data loading on android platform. 引入了加载程序,以便更容易在Android平台上实现正确的数据加载。 This means:
这意味着:
using Handlers,Executors, or AsyncTasks does not take into account all above points. 使用Handler,Executors或AsyncTasks不会考虑以上所有要点。 Your will have to manage this by yourself, and this is the work android developers put into Loaders implementation.
你必须自己管理这个,这是android开发人员在Loaders实现中的工作。
Ie. IE浏览器。 using AsyncTask for loading some data requires you to watch out for screen rotations, ie.
使用AsyncTask加载某些数据需要您注意屏幕旋转,即。 you must somehow retain reference to your AsyncTask that might still do something in background once you activity is recreated due to screen rotation.
你必须以某种方式保留对AsyncTask的引用,一旦你因为屏幕旋转而重新创建活动,它仍然可以在后台执行某些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.