fragment是3.0以后的东西,为了在低版本中使用fragment就要用到android-support-v4.jar兼容包,而fragmentActivity就是这个兼容包里面的,它提供了操作fragment的一些方法,其功能跟3.0及以后的版本的Activity的功能一样。
下面是API中的原话:
FragmentActivity is a special activity provided in the Support Library to handle fragments on system versions older than API level 11. If the lowest system version you support is API level 11 or higher, then you can use a regular Activity. 1、fragmentactivity 继承自activity,用来解决android3.0 之前没有fragment的api,所以在使用的时候需要导入support包,同时继承fragmentActivity,这样在activity中就能嵌入fragment来实现你想要的布局效果。 
2、当然3.0之后你就可以直接继承自Activity,并且在其中嵌入使用fragment了。 
3、获得Manager的方式也不同 
3.0以下:getSupportFragmentManager() 
3.0以上:getFragmentManager() 

Fragment is a section of an Activity, which has:

  • its own lifecycle
  • receives its own input events
  • can be added or removed while the Activity is running.

Fragment must always be embedded in an Activity.

Fragments are not part of the API prior to HoneyComb (3.0). If you want to use Fragments in an app targeting a platform version prior to HoneyComb, you need to add the Support Package to your project and use the FragmentActivity to hold your Fragments. The FragmentActivity class has an API for dealing with Fragments, whereas the Activity class, prior to HoneyComb, doesn't.

If your project is targeting HoneyComb or newer only, you should use Activity and notFragmentActivity to hold your Fragments.

Some details:

Use android.app.Fragment with Activity. Use android.support.v4.app.Fragment withFragmentActivity. Don't add the support package Fragment to an Activity as it will cause an Exception to be thrown.

A thing to be careful with: FragmentManager and LoaderManager have separate support versions for FragmentActivity:

If you are using a Fragment in an Activity (HoneyComb and up), call

  • getFragmentManager() to get android.app.FragmentManager
  • getLoaderManager() to get android.app.LoaderManager

if you are using a Fragment in a FragmentActivity (pre-HoneyComb), call:

  • getSupportFragmentManager() to get android.support.v4.app.FragmentManager.
  • getSupportLoaderManager() to get android.support.v4.app.LoaderManager

so, dont do

myFragmentActivity.getLoaderManager()//don't do this, do myFragmentActivity.getSupportLoaderManager()

or

android.app.FragmentManager fm = myFragmentActivity.getSupportFragmentManager()//don't do this, do android.support.v4.app.FragmentManager fm = myFragmentActivity.getSupportFragmentManager()

Also useful to know is that while a fragment has to be embedded in an Activity it doesn't have to be part of the Activity layout. It can be used as an invisible worker for the activity, with no UI of its own.

http://www.cnblogs.com/wanqieddy/p/3818718.html

FragmentActivity和Activity的具体区别在哪里的更多相关文章

  1. FragmentActivity和Activity的区别

    [转载] 直说总结了: 1.fragmentactivity 继承自activity,用来解决android3.0 之前没有fragment的api,所以在使用的时候需要导入support包,同时继承 ...

  2. AppCompatActivity、ActionBarActivity、FragmentActivity和Activity的区别

    package com.chy.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bu ...

  3. android开发中的 Activity 与 Context 区别与联系

    Context 是 Application /Activity /Service的基类 Intent(Context , Class); Activity中的上下文Context是随着活动的产生而产生 ...

  4. activity启动模式区别和优化

    初学android的开发人员,可能会经常忽略这个重要的设置. Activity一共有以下四种launchMode:1.standard2.singleTop3.singleTask4.singleIn ...

  5. 【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别

    在Activity中可以直接使用Intent启动另一个Activity 显式Intent intent = new Intent(context, activity.class) 隐式 Intent ...

  6. Fragment的startActivityForResult和Activity的startActivityForResult的区别

    2016-08-30 18:22:33 前提:我们的APP要兼容Api level 11以前的,所以必须用FragmentActivity 1.对于Fragment的,我们很多时候都会在Activit ...

  7. Activity 的 36 大难点,你会几个?「建议收藏」

    前言 学 Android 有一段时间了,一直都只顾着学新的东西,最近发现很多平常用的少的东西竟让都忘了,趁着这两天,打算把有关 Activity 的内容以问题的形式梳理出来,也供大家查缺补漏. 本文中 ...

  8. Activity 的 36 大难点,你会几个

    前言 学 Android 有一段时间了,一直都只顾着学新的东西,最近发现很多平常用的少的东西竟让都忘了,趁着这两天,打算把有关 Activity 的内容以问题的形式梳理出来,也供大家查缺补漏. 本文中 ...

  9. Activity是如何挂载Pargment的Day35

    Activity是如何挂载Pargment的Day35 mebile5.0 1.Fragment优化早上任务 思路 一个主Activity 短信群发器 中秋给朋友发短信,都能够加上他们的姓名,这样他们 ...

随机推荐

  1. 【Nginx 1】Nginx 的下载和安装

    今天正式开始学习Nginx.Nginx是一个著名的轻量级Http服务器,目前已经有很多知名网站使用Nginx作为服务器.因为Nginx是开源的软件,因此对于开发人员和学习者来说都是一个大宝藏. 首先, ...

  2. Linux 文件/文件夹操作命令

    1 cd命令 命令格式:cd  [目录名]    (cd和目录之间使用空格隔开) cd      进入用户主目录: cd  ~  进入用户主目录: cd  -  返回进入此目录之前所在的目录: cd  ...

  3. memcached和redis的区别和应用场景

    一:特性和对比 1.性能上:      性能上都很出色,具体到细节,由于Redis只使用单核,而Memcached可以使用多核,所以平均每一个核上Redis在存储小数据时比 Memcached性能更高 ...

  4. echars3.0 柱状图y轴字体斜放

    xAxis: [ { type: 'category', axisLabel: { interval: 0, rotate: 45,//倾斜角度设置,是什么时针未测 margin: 2 //距离上部的 ...

  5. MyBatis(3.2.3) - Configuring MyBatis using XML, typeHandlers

    As discussed in the previous chapter, MyBatis simplifies the persistent logic implementation by abst ...

  6. Ubuntu系统中登陆阿里云服务器的方法

    如果您购买了阿里云服务器,恰巧又在使用Ubuntu操作系统,那么恭喜你来对地方了,今天给大家分享一下如何在Ubuntu中登陆阿里云服务器: 主要使用两款软件:1.SecureCRT:2.SecureF ...

  7. MyEclipse SVN 插件

    一.下载SVN插件subclipse 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 在打开的网 ...

  8. Quartz 第二课 Jobs and Triggers(官方文档翻译)

    The Quartz API IScheduler—与scheduler交互的主要的接口 IJob—这个接口主要定义scheduler执行内容 IJobDetail—用于定义Jobs实例 ITrigg ...

  9. (转)ASP.NET并发处理

    对于DB服务器同样也可以调整最大连接数来做优化. 在调整优化好最大连接数之后,就只有软硬件负载均衡了.硬件负载均衡能够直接通过智能交换机实现,处理能力强,而且与系统无关,但是价格贵,配置困难,不能区分 ...

  10. NodeJS服务器退出:完成任务,优雅退出

    上一篇文章,我们通过一个简单的例子,学习了NodeJS中对客户端的请求(request)对象的解析和处理,整个文件共享的功能已经完成.但是,纵观整个过程,还有两个地方明显需要改进: 首先,不能共享完毕 ...