Android - Activity 与 FragmentActivity? [英] Android - Activity vs FragmentActivity?

查看:33
本文介绍了Android - Activity 与 FragmentActivity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 新手.我想构建一个标签格式的应用程序.我发现了许多使用 Activity 的文档.另外在很多情况下都使用了FragmentActivity.我不确定从哪个开始会更好.请建议我应该使用 Activity 还是 FragmentActivity 以选项卡格式开始开发?

I am new in Android. I want to build an app with tab format. I found many documentation where Activity has been used. Also in many cases have used FragmentActivity. I am not sure which will be better to start. Please suggest me should I use Activity or FragmentActivity to start development in tab format?

推荐答案

ianhanniballake 是对的.您可以从 FragmentActivity 获得 Activity 的所有功能.事实上,FragmentActivity 具有更多功能.

ianhanniballake is right. You can get all the functionality of Activity from FragmentActivity. In fact, FragmentActivity has more functionality.

使用FragmentActivity,您可以轻松构建tab 和swap 格式.对于每个选项卡,您可以使用不同的 Fragment(Fragment 是可重用的).因此,对于任何 FragmentActivity,您都可以重复使用相同的 Fragment.

Using FragmentActivity you can easily build tab and swap format. For each tab you can use different Fragment (Fragments are reusable). So for any FragmentActivity you can reuse the same Fragment.

您仍然可以将 Activity 用于单个页面,例如列出某些内容并在下一页编辑列表元素.

Still you can use Activity for single pages like list down something and edit element of the list in next page.

如果你使用的是android.app.Fragment,还要记得使用Activity;如果您使用 android.support.v4.app.Fragment,请使用 FragmentActivity.切勿将 android.support.v4.app.Fragment 附加到 android.app.Activity,因为这会导致抛出异常.

Also remember to use Activity if you are using android.app.Fragment; use FragmentActivity if you are using android.support.v4.app.Fragment. Never attach a android.support.v4.app.Fragment to an android.app.Activity, as this will cause an exception to be thrown.

这篇关于Android - Activity 与 FragmentActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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