简体   繁体   English

FragmentActivity和Activity之间有什么区别?

[英]What is difference between FragmentActivity and Activity?

我已经在片段活动的基本代码替换活动中使用它,但我没有任何错误。应用程序已经工作。

As seen in the documentation: 如文档中所示:

FragmentActivity FragmentActivity

Base class for activities that want to use the support-based Fragment and Loader APIs. 要使用基于支持的Fragment和Loader API的活动的基类。

Activity 活动

An activity is a single, focused thing that the user can do. 活动是用户可以做的单一,专注的事情。 Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). 几乎所有活动都与用户交互,因此Activity类负责为您创建一个窗口,您可以在其中使用setContentView(View)放置UI。 While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup) 虽然活动通常以全屏窗口的形式呈现给用户,但它们也可以以其他方式使用:浮动窗口(通过带有windowIsFloating集的主题)或嵌入到另一个活动内部(使用ActivityGroup)

Can see more at : http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html 可以在以下网址查看更多信息: http//developer.android.com/reference/android/support/v4/app/FragmentActivity.html

A fragment activity can contain fragments (as it's name implies). 片段活动可以包含片段 (顾名思义)。 It's the support version of activities for older APIs, which want to use fragments. 它是旧API的活动支持版本,它希望使用片段。

A Fragment , introduced in Android 3.0 HoneyComb is a portion of a user interface inside an activity. Android 3.0 HoneyComb引入的Fragment是活动内部用户界面的一部分。 You can have many fragments in you UI. 您可以在UI中包含许多片段。

FragmentActivity is the base class you must extend in order to use fragments with the support library. FragmentActivity是必须扩展的基类,以便将片段与支持库一起使用。

The nuance here is that an Activity can use Fragment s from the native SDK (as long as you are targeting API 11+), while a FragmentActivity can use Fragment s from the support library. 这里的细微差别在于, Activity可以使用本机SDK中的Fragment (只要您的目标是API 11+),而FragmentActivity可以使用支持库中的Fragment

So, assuming API 11+, if you are using android.app.Fragment s in your app, you can use Activity , but if you are using android.support.v4.app.Fragment s in your app, then you must use FragmentActivity . 因此,假设API 11+,如果您在应用程序中使用android.app.Fragment ,则可以使用Activity ,但如果您在应用程序中使用android.support.v4.app.Fragment ,则必须使用FragmentActivity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM