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 短信群发器 中秋给朋友发短信,都能够加上他们的姓名,这样他们 ...
随机推荐
- 用RSA实现Web单点登录密码的加密传输
在使用通用权限管理系统(吉日嘎拉)的单点登录功能时,对登录密码使用了RSA加密(非对称加密),有使用这个权限管理系统的可参考下. 前端部分,请引用以下几个js文件: <script type=& ...
- Debian 7.4 中配置PHP环境
准备工作 导入密钥 wget http://www.dotdeb.org/dotdeb.gpg sudo apt-key add dotdeb.gpg 添加源 vi /etc/apt/sources. ...
- java 类从哪个jar包加载的
<%@page contentType="text/html; charset=GBK"%><%@page import="java.security. ...
- 转载:Restore SQL Server database and overwrite existing database
转载自:https://www.mssqltips.com/sqlservertutorial/121/restore-sql-server-database-and-overwrite-existi ...
- 【欧拉定理】计算(a^(b^c))%1000000007
欧拉定理(称费马-欧拉定理或欧拉 函数定理) 欧拉定理表明,若n,a为正整数,且n,a互素(即gcd(a,n)=1),则 这个定理可以用来简化幂的模运算.比如计算7222的个位数,实际是求7222被1 ...
- hdu 1195 广度搜索
这题我们可以用优先队列,每次弹出队列中操作次数最少的一个,那么当找到匹配数时,该值一定是最优的.需要注意的时,加个vi[]数组,判读当前数是否已经存在于队列中.我做的很烦啊~~~ #include&l ...
- Dynamic\Static\IsKinematic
1.Dynamic: 有Collider和RigidBody的GameObject, Unity视之为Dynamic. 适用于经常变换移动的对象. 2.Static: 只含有Collider的Game ...
- Linux 命令 - mkdir: 创建目录
命令格式 mkdir [OPTION]... DIRECTORY... 命令参数 -m, --mode=MODE 设置文件的模式,类似于 chmod 命令. -p, --parents 需要时创建指定 ...
- java开发:分享一下使用urlrewrite实现网址的个性访问
很多网站都有一些比较个性的域名访问方式,如:http://www.xxx.com/u/pp 点开就可以看到pp的个人主页了,这种地址比较容易让人记住,那今天就来讲讲这种技术的实现方式. 1.使用ja ...
- centos6.5下磁盘创建交换分区
1.创建磁盘交换分区 2.创建文件交换分区