FragmentActivity和Activity的具体区别在哪里
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()
A 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.
A 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 getandroid.app.FragmentManager
getLoaderManager()
to getandroid.app.LoaderManager
if you are using a Fragment
in a FragmentActivity
(pre-HoneyComb), call:
getSupportFragmentManager()
to getandroid.support.v4.app.FragmentManager
.getSupportLoaderManager()
to getandroid.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的具体区别在哪里的更多相关文章
- FragmentActivity和Activity的区别
[转载] 直说总结了: 1.fragmentactivity 继承自activity,用来解决android3.0 之前没有fragment的api,所以在使用的时候需要导入support包,同时继承 ...
- AppCompatActivity、ActionBarActivity、FragmentActivity和Activity的区别
package com.chy.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bu ...
- android开发中的 Activity 与 Context 区别与联系
Context 是 Application /Activity /Service的基类 Intent(Context , Class); Activity中的上下文Context是随着活动的产生而产生 ...
- activity启动模式区别和优化
初学android的开发人员,可能会经常忽略这个重要的设置. Activity一共有以下四种launchMode:1.standard2.singleTop3.singleTask4.singleIn ...
- 【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别
在Activity中可以直接使用Intent启动另一个Activity 显式Intent intent = new Intent(context, activity.class) 隐式 Intent ...
- Fragment的startActivityForResult和Activity的startActivityForResult的区别
2016-08-30 18:22:33 前提:我们的APP要兼容Api level 11以前的,所以必须用FragmentActivity 1.对于Fragment的,我们很多时候都会在Activit ...
- Activity 的 36 大难点,你会几个?「建议收藏」
前言 学 Android 有一段时间了,一直都只顾着学新的东西,最近发现很多平常用的少的东西竟让都忘了,趁着这两天,打算把有关 Activity 的内容以问题的形式梳理出来,也供大家查缺补漏. 本文中 ...
- Activity 的 36 大难点,你会几个
前言 学 Android 有一段时间了,一直都只顾着学新的东西,最近发现很多平常用的少的东西竟让都忘了,趁着这两天,打算把有关 Activity 的内容以问题的形式梳理出来,也供大家查缺补漏. 本文中 ...
- Activity是如何挂载Pargment的Day35
Activity是如何挂载Pargment的Day35 mebile5.0 1.Fragment优化早上任务 思路 一个主Activity 短信群发器 中秋给朋友发短信,都能够加上他们的姓名,这样他们 ...
随机推荐
- iOS银行卡合法性校验
项目中用到了校验银行卡,就拿来贴上来了 + (BOOL)checkCardNo:(NSString*)cardNo;//判断银行卡 + (BOOL)checkCardNo:(NSString*)car ...
- Eclipse NDK 配置,无需安装Cygwin
Eclipse NDK 配置,不用安装Cygwin 文章转自http://www.cnblogs.com/chenjiajin/archive/2012/04/12/2444188.html 一.关于 ...
- MVC清除缓存设置+数据验证
[OutputCache(Location = OutputCacheLocation.None, NoStore = true)] [Table("User")]:定义UserD ...
- web-app1--移动端等比例代码
1 : <meat name="viewport" content="width=device-width,initial-scale=1"/> ...
- JMS - 消息确认
消息确认机制 消息确认协议是保证消息传送的关键所在,同时,支持确认也是 JMS API 语义的要求.以下将分别从消息生产者.消息服务器.消息消费者的角度,来考察消息确认机制. 从消息生产者的角度考察 ...
- HDOJ2026首字母变大写
首字母变大写 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 解析LRC歌词文件readlrc
package com.jikexueyuan.readlrc.main; import com.jikexueyuan.readlrc.utils.Utils; import java.io.Fil ...
- 消息推送SignalR
一.什么是 SignalR ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of add ...
- 一个简单的Makefile的编写【用自己的话,解释清楚这些】
用自己的话,解释清楚这些~ Makefile是程序员编写出来指导编译器编译程序源码为目标文件(可执行文件,或链接库) 这里只写一个简单的Makefile 作为例子 其需求如下: frank@ubunt ...
- linux(ubuntu)和windows下面快速搭建android开发环境
在windows和linux下面搭建android开发环境,一般要安装以下几个软件: 1.JDK安装 2.Eclipse安装 3.Android SDK安装 4.在eclipse里面安装ADT 5.e ...