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 短信群发器 中秋给朋友发短信,都能够加上他们的姓名,这样他们 ...
随机推荐
- c语言排序算法总结
一.希尔(Shell)排序法 /* Shell 排序法 */ #include <stdio.h> void sort(int v[],int n) { int gap,i,j, ...
- SQL_server 数据库备份信息查看
select distinct s.database_name, s.first_lsn,s.last_lsn,s.database_backup_lsn,s.backup_finish_date,s ...
- VMware系统运维(三 )SQL Server 2008 R2安装
1. 点击"全新SQL Server 独立安装或向现有安装添加功能" 2.验证通过,点击确定. 3.输入数据库密钥,必须支持正版,不然微软打你屁屁,嘻嘻 4.不接受不让你过,所以不 ...
- 网络编程(发送get和post请求到服务器端,并获取响应)
一:B/S结构,浏览器端到服务器端通信依赖http协议 交互过程: 1:在浏览器地址栏输入http://ip:port/应用/资源路径 2:浏览器根据ip和服务器建立连接,port确定和那个应用进行交 ...
- template和templateUrl区别与联系
templateUrl其实根template功能是一样的,只不过templateUrl加载一个html文件,template后面根的是html的标签. .state('menu.about', { u ...
- 【最短路】ACdream 1198 - Transformers' Mission
Problem Description A group of transformers whose leader is Optimus Prime(擎天柱) were assigned a missi ...
- Angular2 从0到1 (一)
史上最简单Angular2教程,大叔都学会了 作者:王芃 wpcfan@gmail.com 第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:An ...
- saltstack实战2--远程执行之目标(target)
target 就是目标的意思,你要在那台机器上执行此命令或此状态.或者说将此动作或者状态文件推送给谁来执行,让那个minion执行可以进行一些匹配 对于拥有大量机器的环境,如果单独一台台的执行指定mi ...
- c# 与 PHP中 SHA1加密结果不同解决方法
那天在调试API的时候,发现用c#写的SHA1加密出来的结果和PHP中sha1()出来的不一样,找了半天的原因后来才弄出来 在调试微信接口的时候大多的帮助文档都是提供的是PHP的方法,所以在.net中 ...
- Service通信详解
1.使用Intent进行异步通讯 在Service任务一旦完成后,就发送广播.开发者只需要实现一个BroadcastReceiver来监听响应既可. Activity.startService启动in ...