有什么用例,没有UI中的片段? [英] What is the use case for a Fragment with no UI?

查看:114
本文介绍了有什么用例,没有UI中的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android开发指南对使用碎片一个体面的部分。使用片段的方法之一是没有的UI。有几个参考使用此作为后台处理的手段,但是优势并片段为这一领域?我会在哪里选择使用片段在线程,AsyncTasks,处理程序等,为后台处理?

The Android Developer guide has a decent section on the use of Fragments. One way to use Fragments is without a UI. There are a few references to using this as a means of background processing, but what advantages do Fragments bring to this area? Where would I choose to use a Fragment over Threads, AsyncTasks, Handlers, etc. for background processing?

推荐答案

A 片段实例可以通过设备配置变化(如屏幕旋转)依然存在。因为一个活动将被销毁并重新创建时,配置的变化情况,这是很难设计之一,将跟踪线程或的AsyncTask 。在另一方面,该系统需要重新连接照顾一个持续片段到正确的活动在另一端(所以说话)的配置变化。你仍然可以使用线程或的AsyncTask ,只是现在的片段拿着它来代替。

A Fragment instance can persist through device configuration changes (like screen rotation). Because an Activity will be destroyed and recreated when a configuration change happens, it's difficult to design one that will keep track of a thread or AsyncTask. On the other hand, the system takes care of reattaching a persisted Fragment to the proper Activity at the other end (so to speak) of the configuration change. You would still be using a thread or AsyncTask, only now the Fragment is holding it instead.

可能还有其他用途,但有一个我能想到的。

There may be other uses for it, but there's the one I can think of.

这篇关于有什么用例,没有UI中的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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