FragmentActivity和Activity的具体区别在哪里

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

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() 



http://www.dotblogs.com.tw/newmonkey48/archive/2014/07/04/145804.aspx


比較重點的會是在

Also remember use Activity if you are using android.app.Fragment; use FragmentActivity if you are using android.support.v4.app.Fragment. Never attach a android.support.v4.app.Fragment to a android.app.Activity, as this will cause an exception to be thrown.

其實意思應該是如果你使用的是android.app.Fragment 的類別時,需使用android.app.Activity

若是使用 android.support.v4.app.Fragment,則需使用FragmentActivity。

若搭配錯誤的話,則會出現Exception


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值