使用:

    private Fragment fragment;private FragmentManager fm;fm = getSupportFragmentManager();fragment = fm.findFragmentById(R.id.fragment_container);fm.beginTransaction().add(R.id.fragment_container, fragment).commit();

beginTransaction源码:

 /*** Start a series of edit operations on the Fragments associated with* this FragmentManager.** <p>Note: A fragment transaction can only be created/committed prior* to an activity saving its state.  If you try to commit a transaction* after {@link FragmentActivity#onSaveInstanceState FragmentActivity.onSaveInstanceState()}* (and prior to a following {@link FragmentActivity#onStart FragmentActivity.onStart}* or {@link FragmentActivity#onResume FragmentActivity.onResume()}, you will get an error.* This is because the framework takes care of saving your current fragments* in the state, and if changes are made after the state is saved then they* will be lost.</p>*/public abstract FragmentTransaction beginTransaction();

add源码:

/*** Calls {@link #add(int, Fragment, String)} with a null tag.*/public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

commit源码:

 /*** Schedules a commit of this transaction.  The commit does* not happen immediately; it will be scheduled as work on the main thread* to be done the next time that thread is ready.** <p class="note">A transaction can only be committed with this method* prior to its containing activity saving its state.  If the commit is* attempted after that point, an exception will be thrown.  This is* because the state after the commit can be lost if the activity needs to* be restored from its state.  See {@link #commitAllowingStateLoss()} for* situations where it may be okay to lose the commit.</p>* * @return Returns the identifier of this transaction's back stack entry,* if {@link #addToBackStack(String)} had been called.  Otherwise, returns* a negative number.*/public abstract int commit();

Android FragmentManager之beginTransaction()相关推荐

  1. Android Fragment使用(三) Activity, Fragment, WebView的状态保存和恢复

    Android中的状态保存和恢复 Android中的状态保存和恢复, 包括Activity和Fragment以及其中View的状态处理. Activity的状态除了其中的View和Fragment的状 ...

  2. 【Android】Fragment的简单笔记

    被虐了,做某公司笔试时,发现自己连个Fragment的生命周期都写不详细.平时敲代码,有开发工具的便利,有网上各大神的文章,就算忘了也很容易的可以查到,但当要自己不借助外界,却发现自己似乎对该知识点并 ...

  3. Android系列之Fragment(一)----Fragment加载到Activity当中

    参考文章出处: 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3978989.html 前言 A ...

  4. Android 的 Fragment 教程

    原文:Introduction to Android Fragments Tutorial 作者:Huyen Tue Dao 译者:kmyhy 一个 fragment 可以是任何东西,但在本文中,它是 ...

  5. Android第一行代码学习思考笔记(碎片、广播、持久化技术和Android数据库)

    Android第一行代码学习思考笔记(碎片.广播.持久化技术和Android数据库 第四章 手机平板要兼顾--探究碎片 4.1碎片是什么(Fragment) 4.2碎片的使用方式 4.2.1碎片的简单 ...

  6. android 小练习(一) ---仿微信UI主界面

    ActionBar 相信大家都用过微信,微信的界面我们从上往下看,首先是一个ActionBar,并且自定义了ActionProvider,就是那个"加号",里面有五个子菜单.今天就 ...

  7. Wcdb android 目录,wcdb使用笔记

    本地数据加密 由于项目涉及到一些用户隐私数据的存储,所以需要对保存在客户端本地的数据进行加密,以防止用户隐私数据在设备被root的情况下出现泄漏.目前android的本地数据存储基本分为file,sh ...

  8. Android 4.0.3 联系人(通讯录)应用源码学习

    Contacts应用入口类有2个:PeopleActivity.java和DialtactsActivity.java.PeopleActivity是联系人入口类,DialtactsActivity是 ...

  9. 底部导航栏的几种实现方式

    概述 Android底部导航栏实现方式真的是太多了~在这里仅介绍几种实现方式~建议使用TabLayout +ViewPager ,TabLayout是Android Material Design中的 ...

最新文章

  1. Winform应用程序实现通用遮罩层二
  2. pycharm python 如何快速给代码块添加try/catch try/finally包裹?【ctrl+alt+T】
  3. InnoDB锁机制之Gap Lock、Next-Key Lock、Record Lock解析
  4. [转]I,P,B帧和PTS,DTS的关系
  5. list下界_下界理论
  6. AI队列长度检测:使用YOLO进行图像中的对象检测
  7. 在MyEclipse中配置Tomcat服务器
  8. CSS:transform
  9. 用CIL写程序:从“call vs callvirt”看方法调用
  10. 三码合一方法 制作QQ、微信、支付宝收款码合一
  11. XRD进行定性分析时可以得到哪些有用信息
  12. 刷armbian后必要的安装和配置
  13. mysql中if多重判断使用
  14. Python学员信息管理系统
  15. ipad查看电脑中的文件
  16. vs进行cuda编程失败,报错“the provided PTX was compiled with an unsupported toolchain.”
  17. 飞鸽传书——短信接口
  18. 用python读取身份证信息的功能分析与实现,兼述python调用dll的方法
  19. 微信分享网页链接自定义标题,图片,文字描述
  20. Java8 方法引用和Stream流

热门文章

  1. SpringMVC消息转换器
  2. airodump-ng的使用及显示
  3. java/php/net/pythont中医体质的社区居民健康管理设计
  4. 球面贴图(Sphere Map)
  5. 它的身体像鸡蛋飞秋下载
  6. 基于matlab信道均衡仿真,基于MATLAB的数字自适应信道均衡器仿真研究.doc
  7. 零基础入门3D游戏建模师知识必备
  8. 基于51单片机空气环境粉尘检测PM2.5 风扇控制系统设计
  9. SPSS和Mplus如何做非线性中介调节效应分析?如倒U形曲线
  10. 数据库村的旺财和小强