• android学习八 多用途碎片


    碎片设计初衷:帮助开发人员管理应用程序功能。

    特点:1.大量重用
              2.可用性强
              3.适应多种布局
              
    碎片 1.包含一个视图层次结构和具有相应的生命周期
            2.碎片必须在一个活动的上下文中工作
            3.碎片的生命周期和活动很相似
            4.但在状态的保存与恢复上与活动有区别
     
    碎片的优点:
            a.在布局管理的时候可以直接作用于布局本身,而不必理会碎片内部
            b.碎片的状态容易保存和恢复
            c.可以将碎片添加到后退栈,实现在活动内按back键回退到上一个碎片
            d.碎片的切换可以有多种特效
     
    碎片的结构
             a.碎片的基类继承自 android.app.Object类,而不是activity的context类
             b.碎片的视图层次结构
             c.因为碎片在恢复时会调用默认的构造函数,所以必须确保碎片类有默认的构造函数
             d.由于碎片的恢复需要,所以在创建碎片后最好指定参数包,并适当设置,以供恢复时使用。
             e.碎片的状态可以保存到包,像activity一样,在后续的回调(onCreate,onInflate,onActivityCreated)中调用。
     
    碎片的标示:
              由于碎片可以被管理,所以拥有一些自身的识别信息,包括一个标示和一个ID.
     
    碎片的生命周期:
     
    主要关注虚线部分,因为虚线部分会跳过一些回调
     
    setArguments()方法只能在on_attach前调用,而在其后的整个生命周期都可以调用getArguments.
     
    回调函数说明(按照常规调用顺序排列)
     
    onInflate():如果是通过<fragment>标签扩充则会包括属性列表AttributeSet,如果之前有调用onSaveInstanceState()则会包括一个状态包Bundle。 不要对界面做任何操作setArguments()方法只能在onattach前调用,而在其后的整个生命周期都可以调用getArguments.
    onAttach(): 将传入Activity(可以在这个时刻保存其引用,也可以在下面的任何时候通过getActivity()获取。
    onCreate(): 不应该有任何与界面相关的操作,因为活动还未创建完成。这里能获取到保存的状态包。
    onCreateView():不要将试图附加到传入的容器中。inflate的第三个参数为false。
    onActivityCreated():用户界面的最后调整机会,这里确保其他碎片已经附加到活动中。
    onStart():同活动的onStart绑定,以前放在onStart中的逻辑,现在可以放在这里。
    onResume():同活动的onResume绑定,以前放在中的逻辑,现在可以放在这里。
    onSaveInstanceState():保存需要保存的数据导包里面
    onPause():避免耗资源的操作
    onStop():
    onDestoryView()
    onDestory()
    onDetach()
     
     
    setRetainInstance(true)表示在活动重建的过程中,不调用onDestory删除内存中碎片对象,方便恢复。而调用该函数的最佳位置是onCreate中。 因为调用这个函数后 流程很可能如下onDestoryView->跳过onDestory直接调用onDetach->onInflate->onAttach->跳过onCreate直接调用onCreateView 。 因此在这种情况下需要考虑onCreate的逻辑,因为会被跳过不执行。
     
    编程注意事项
    1.<fragment>标签有一个指定碎片类的class属性。因为<fragment>标签只是占位符所以在其下不应该有子标签。
    2.要达到动态切换碎片的目标,就需要有一个容器。例如在<fragment>标签下声明一个<FrameLayout>
    3.判断横屏的方法 if(getResources()->getConfigration()->orentation=Configuration.ORIENTATION_LANDSCAPE)
    4.可以通过setTransction()方法和setCustomAnimations()方法设置碎片的过渡效果。
    5.动态碎片的一般代码结构
             FragmentManager.startFragmentTransction().add()/replace()/hide()/show()/remove().commit();
    6.在活动中获取碎片管理器 getFragmentManager()
    7.可以使用活动的碎片管理器来获取事务(getFragmentTransction()),获取碎片(findFragmentById()/findFragmentByTag()/getFragment()这个与putFragment搭配使用),从后退栈中删除指定ID或指定位置的碎片。
     
    8.可以通过添加没有视图结构的碎片作为setRetainInstance()的备选方案。
    9.因为在多种情况下会将碎片保存且切出内存,所以不应该长时间保存碎片的引用,而应该通FragmentManager.fndFragmentById来实现。
     
    10.ListFragment类
     
    11.当前活动的顶级视图容器 android.R.id.content

    12.由于可以在活动或碎片中获取FragmentManager,而FragmentManager又能获取任意碎片的引用,所以在活动或碎片中操作其他碎片很容易。
     
    13.碎片的直接通信
         FragmentOther fragOther = 

    (FragmentOther)getFragmentManager().findFragmentByTag(“other”);
    fragOther.callCustomMethod( arg1, arg2 );

     
    14.与目标碎片的通信。A碎片创建B碎片,B碎片将A碎片设置为目标碎片,B碎片设置A碎片的内容。
     
    //A碎片创建B碎片
    mCalledFragment = new CalledFragment();
    mCalledFragment.setTargetFragment(this, 0);  //B碎片将当前的A碎片设置为目标碎片
    fm.beginTransaction().add(mCalledFragment, "work").commit(); 
     
    TextView tv = (TextView)
    getTargetFragment().getView().findViewById(R.id.text1);
    tv.setText(“Set from the called fragment”); 
     

     
     
    后退栈:可以通过创建和管理FragmentTransction来让碎片参与到后退栈中(FragmentTransction.addToBackStack()),实现活动内部碎片级别的back按钮。如果不实现,则活动的所有碎片都与活动同步回滚。
     
     
    示例程序的时序:(竖屏进入应用,按back键回退到主活动,按标题进入详细碎片,横屏)
    10-19 00:59:49.440: V/FragmentLifeTimeTest Log:(7837): MainActivity.onCreate is called!
    10-19 00:59:49.450: V/FragmentManager(7837): onCreateView: id=0x7f090041 fname=com.example.fragmentlifetimetest.TitleFragment existing=null
    10-19 00:59:49.450: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onInflate is called!
    10-19 00:59:49.450: V/FragmentLifeTimeTest Log:(7837): id = @2131296321
    10-19 00:59:49.450: V/FragmentLifeTimeTest Log:(7837): layout_width = -1
    10-19 00:59:49.450: V/FragmentLifeTimeTest Log:(7837): layout_height = -1
    10-19 00:59:49.450: V/FragmentLifeTimeTest Log:(7837): class = com.example.fragmentlifetimetest.TitleFragment
    10-19 00:59:49.450: V/FragmentManager(7837): add: TitleFragment{42608e10 id=0x7f090041}
    10-19 00:59:49.450: V/FragmentManager(7837): Allocated fragment index TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.460: V/FragmentManager(7837): moveto CREATED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onAttach is called!
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): in MainActivity onAttachFragment. fragment id = 2131296321
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onCreate is called!
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onCreateView is called!
    10-19 00:59:49.460: V/FragmentLifeTimeTest Log:(7837): MainActivity.onStart is called!
    10-19 00:59:49.490: V/FragmentManager(7837): moveto ACTIVITY_CREATED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.490: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onActivityCreated is called!
    10-19 00:59:49.490: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:49.490: V/FragmentLifeTimeTest Log:(7837): MainActivity.showDetail is called!
    10-19 00:59:49.520: V/FragmentManager(7837): moveto STARTED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.520: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onStart is called!
    10-19 00:59:49.520: V/FragmentLifeTimeTest Log:(7837): MainActivity.onResume is called!
    10-19 00:59:49.520: V/FragmentManager(7837): moveto RESUMED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.520: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onResume is called!
    10-19 00:59:49.520: V/FragmentLifeTimeTest Log:(7837): MainActivity.onSaveInstanceState is called!
    10-19 00:59:49.520: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onSaveInstanceState is called! save curChoice=0
    10-19 00:59:49.530: V/FragmentManager(7837): Saved state of TitleFragment{42608e10 #0 id=0x7f090041}: Bundle[{android:view_state=android.util.SparseArray@4260f6d8, curChoice=0}]
    10-19 00:59:49.530: V/FragmentManager(7837): saveAllState: adding fragment #0: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.530: V/FragmentLifeTimeTest Log:(7837): MainActivity.onPause is called!
    10-19 00:59:49.530: V/FragmentManager(7837): movefrom RESUMED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.530: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onPause is called!
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onCreate called!
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailFragment.newInstance(Bundle) called! index=0
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailFragment.newInstance(int) called! index=0
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): newInstance end
    10-19 00:59:49.580: V/FragmentManager(7837): Commit: BackStackEntry{42615220}
    10-19 00:59:49.580: D/FragmentManager(7837):   mName=null mIndex=-1 mCommitted=false
    10-19 00:59:49.580: D/FragmentManager(7837):   Operations:
    10-19 00:59:49.580: D/FragmentManager(7837):     Op #0: ADD DetailFragment{42615098 id=0x1020002}
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onStart begin
    10-19 00:59:49.580: V/FragmentManager(7837): Run: BackStackEntry{42615220}
    10-19 00:59:49.580: V/FragmentManager(7837): add: DetailFragment{42615098 id=0x1020002}
    10-19 00:59:49.580: V/FragmentManager(7837): Allocated fragment index DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:49.580: V/FragmentManager(7837): moveto CREATED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onAttach called!
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreate called!
    10-19 00:59:49.580: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:49.580: V/FragmentManager(7837): moveto ACTIVITY_CREATED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreateView called!
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onActivityCreated called!
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:49.590: V/FragmentManager(7837): moveto STARTED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onStart called!
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onResume begin
    10-19 00:59:49.590: V/FragmentManager(7837): moveto RESUMED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:49.590: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onResume called!
    10-19 00:59:49.870: V/FragmentLifeTimeTest Log:(7837): MainActivity.onStop is called!
    10-19 00:59:49.870: V/FragmentManager(7837): movefrom STARTED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:49.870: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onStop is called!
    10-19 00:59:49.870: V/FragmentManager(7837): movefrom STOPPED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:52.533: V/FragmentLifeTimeTest Log:(7837): DetailActivity.finish begin
    10-19 00:59:52.543: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onPause begin
    10-19 00:59:52.543: V/FragmentManager(7837): movefrom RESUMED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:52.543: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onPause called!
    10-19 00:59:52.563: V/FragmentLifeTimeTest Log:(7837): MainActivity.onStart is called!
    10-19 00:59:52.563: V/FragmentManager(7837): moveto STARTED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:52.563: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onStart is called!
    10-19 00:59:52.563: V/FragmentLifeTimeTest Log:(7837): MainActivity.onResume is called!
    10-19 00:59:52.563: V/FragmentManager(7837): moveto RESUMED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:52.563: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onResume is called!
    10-19 00:59:52.833: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onStop begin
    10-19 00:59:52.833: V/FragmentManager(7837): movefrom STARTED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:52.843: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onStop called!
    10-19 00:59:52.843: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onDestroy begin
    10-19 00:59:52.843: V/FragmentManager(7837): movefrom STOPPED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:52.843: V/FragmentManager(7837): movefrom ACTIVITY_CREATED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:52.843: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroyView called! view=android.support.v4.app.NoSaveStateFrameLayout@4261b5d8
    10-19 00:59:52.843: V/FragmentManager(7837): movefrom CREATED: DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:52.853: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroy called!
    10-19 00:59:52.853: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDetach called!
    10-19 00:59:52.853: V/FragmentManager(7837): Freeing fragment index DetailFragment{42615098 #0 id=0x1020002}
    10-19 00:59:55.596: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onListItemClick is called! position=3
    10-19 00:59:55.596: V/FragmentLifeTimeTest Log:(7837): MainActivity.showDetail is called!
    10-19 00:59:55.616: V/FragmentLifeTimeTest Log:(7837): MainActivity.onSaveInstanceState is called!
    10-19 00:59:55.616: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onSaveInstanceState is called! save curChoice=3
    10-19 00:59:55.626: V/FragmentManager(7837): Saved state of TitleFragment{42608e10 #0 id=0x7f090041}: Bundle[{android:view_state=android.util.SparseArray@42622708, curChoice=3}]
    10-19 00:59:55.626: V/FragmentManager(7837): saveAllState: adding fragment #0: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:55.626: V/FragmentLifeTimeTest Log:(7837): MainActivity.onPause is called!
    10-19 00:59:55.626: V/FragmentManager(7837): movefrom RESUMED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:55.626: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onPause is called!
    10-19 00:59:55.646: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onCreate called!
    10-19 00:59:55.646: V/FragmentLifeTimeTest Log:(7837): DetailFragment.newInstance(Bundle) called! index=3
    10-19 00:59:55.646: V/FragmentLifeTimeTest Log:(7837): DetailFragment.newInstance(int) called! index=3
    10-19 00:59:55.646: V/FragmentLifeTimeTest Log:(7837): newInstance end
    10-19 00:59:55.646: V/FragmentManager(7837): Commit: BackStackEntry{42625790}
    10-19 00:59:55.646: D/FragmentManager(7837):   mName=null mIndex=-1 mCommitted=false
    10-19 00:59:55.646: D/FragmentManager(7837):   Operations:
    10-19 00:59:55.646: D/FragmentManager(7837):     Op #0: ADD DetailFragment{42625608 id=0x1020002}
    10-19 00:59:55.646: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onStart begin
    10-19 00:59:55.646: V/FragmentManager(7837): Run: BackStackEntry{42625790}
    10-19 00:59:55.646: V/FragmentManager(7837): add: DetailFragment{42625608 id=0x1020002}
    10-19 00:59:55.656: V/FragmentManager(7837): Allocated fragment index DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:55.656: V/FragmentManager(7837): moveto CREATED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onAttach called!
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreate called!
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:55.656: V/FragmentManager(7837): moveto ACTIVITY_CREATED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreateView called!
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onActivityCreated called!
    10-19 00:59:55.656: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:55.656: V/FragmentManager(7837): moveto STARTED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:55.666: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onStart called!
    10-19 00:59:55.666: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onResume begin
    10-19 00:59:55.666: V/FragmentManager(7837): moveto RESUMED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:55.666: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onResume called!
    10-19 00:59:55.997: V/FragmentLifeTimeTest Log:(7837): MainActivity.onStop is called!
    10-19 00:59:55.997: V/FragmentManager(7837): movefrom STARTED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:55.997: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onStop is called!
    10-19 00:59:55.997: V/FragmentManager(7837): movefrom STOPPED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onSaveInstanceState begin
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onSaveInstanceState called!
    10-19 00:59:58.249: V/FragmentManager(7837): Saved state of DetailFragment{42625608 #0 id=0x1020002}: Bundle[{android:view_state=android.util.SparseArray@4262f850}]
    10-19 00:59:58.249: V/FragmentManager(7837): saveAllState: adding fragment #0: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onPause begin
    10-19 00:59:58.249: V/FragmentManager(7837): movefrom RESUMED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onPause called!
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onStop begin
    10-19 00:59:58.249: V/FragmentManager(7837): movefrom STARTED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.249: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onStop called!
    10-19 00:59:58.249: V/FragmentManager(7837): movefrom STOPPED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.259: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onDestroy begin
    10-19 00:59:58.259: V/FragmentManager(7837): movefrom ACTIVITY_CREATED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.269: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroyView called! view=android.support.v4.app.NoSaveStateFrameLayout@4262b760
    10-19 00:59:58.269: V/FragmentManager(7837): movefrom CREATED: DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.269: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroy called!
    10-19 00:59:58.269: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDetach called!
    10-19 00:59:58.269: V/FragmentManager(7837): Freeing fragment index DetailFragment{42625608 #0 id=0x1020002}
    10-19 00:59:58.299: V/FragmentManager(7837): Instantiated fragment DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.299: V/FragmentManager(7837): restoreAllState: active #0: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.299: V/FragmentManager(7837): restoreAllState: added #0: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.299: V/FragmentManager(7837): moveto CREATED: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.299: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onAttach called!
    10-19 00:59:58.299: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreate called!
    10-19 00:59:58.299: V/FragmentLifeTimeTest Log:(7837): key = android:view_state
    10-19 00:59:58.299: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onCreate called!
    10-19 00:59:58.299: V/FragmentLifeTimeTest Log:(7837): DetailActivity.finish begin
    10-19 00:59:58.329: V/FragmentLifeTimeTest Log:(7837): MainActivity.onDestroy is called!
    10-19 00:59:58.329: V/FragmentManager(7837): movefrom ACTIVITY_CREATED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:58.329: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onDestroyView is called! view=android.support.v4.app.NoSaveStateFrameLayout@4260cae8
    10-19 00:59:58.329: V/FragmentManager(7837): movefrom CREATED: TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:58.329: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onDestroy is called!
    10-19 00:59:58.329: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onDetach is called!
    10-19 00:59:58.329: V/FragmentManager(7837): Freeing fragment index TitleFragment{42608e10 #0 id=0x7f090041}
    10-19 00:59:58.339: V/FragmentLifeTimeTest Log:(7837): MainActivity.onCreate is called!
    10-19 00:59:58.339: V/FragmentManager(7837): Instantiated fragment TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.339: V/FragmentManager(7837): restoreAllState: active #0: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.339: V/FragmentManager(7837): restoreAllState: added #0: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.339: V/FragmentManager(7837): onCreateView: id=0x7f090041 fname=com.example.fragmentlifetimetest.TitleFragment existing=TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.339: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onInflate is called!
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): id = @2131296321
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): background = #550033
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): layout_width = 0.0px
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): layout_height = -1
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): layout_weight = 1.0
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): class = com.example.fragmentlifetimetest.TitleFragment
    10-19 00:59:58.349: V/FragmentManager(7837): moveto CREATED: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onAttach is called!
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): in MainActivity onAttachFragment. fragment id = 2131296321
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onCreate is called!
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): Key=android:view_state
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): Key=curChoice
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onCreateView is called!
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): MainActivity.onStart is called!
    10-19 00:59:58.349: V/FragmentManager(7837): moveto ACTIVITY_CREATED: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onActivityCreated is called!
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): Key=android:view_state
    10-19 00:59:58.349: V/FragmentLifeTimeTest Log:(7837): Key=curChoice
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): MainActivity.showDetail is called!
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): about to run FragmentTransaction...
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): DetailFragment.newInstance(int) called! index=3
    10-19 00:59:58.359: V/FragmentManager(7837): Commit: BackStackEntry{42640dc0}
    10-19 00:59:58.359: D/FragmentManager(7837):   mName=null mIndex=-1 mCommitted=false
    10-19 00:59:58.359: D/FragmentManager(7837):   mEnterAnim=#10a0000 mExitAnim=#10a0001
    10-19 00:59:58.359: D/FragmentManager(7837):   Operations:
    10-19 00:59:58.359: D/FragmentManager(7837):     Op #0: REPLACE DetailFragment{42640c38 id=0x7f090042}
    10-19 00:59:58.359: D/FragmentManager(7837):   enterAnim=#10a0000 exitAnim=#10a0001
    10-19 00:59:58.359: V/FragmentManager(7837): Run: BackStackEntry{42640dc0}
    10-19 00:59:58.359: V/FragmentManager(7837): OP_REPLACE: adding=DetailFragment{42640c38 id=0x7f090042} old=TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.359: V/FragmentManager(7837): add: DetailFragment{42640c38 id=0x7f090042}
    10-19 00:59:58.359: V/FragmentManager(7837): Allocated fragment index DetailFragment{42640c38 #1 id=0x7f090042}
    10-19 00:59:58.359: V/FragmentManager(7837): moveto CREATED: DetailFragment{42640c38 #1 id=0x7f090042}
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onAttach called!
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): in MainActivity onAttachFragment. fragment id = 2131296322
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreate called!
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:58.359: V/FragmentManager(7837): moveto ACTIVITY_CREATED: DetailFragment{42640c38 #1 id=0x7f090042}
    10-19 00:59:58.359: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreateView called!
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onActivityCreated called!
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): savedInstanceState is null!
    10-19 00:59:58.369: V/FragmentManager(7837): moveto STARTED: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onStart is called!
    10-19 00:59:58.369: V/FragmentManager(7837): moveto STARTED: DetailFragment{42640c38 #1 id=0x7f090042}
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onStart called!
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): MainActivity.onResume is called!
    10-19 00:59:58.369: V/FragmentManager(7837): moveto RESUMED: TitleFragment{42636b58 #0 id=0x7f090041}
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): TitleFragment.onResume is called!
    10-19 00:59:58.369: V/FragmentManager(7837): moveto RESUMED: DetailFragment{42640c38 #1 id=0x7f090042}
    10-19 00:59:58.369: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onResume called!
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailActivity.onDestroy begin
    10-19 00:59:58.489: V/FragmentManager(7837): moveto ACTIVITY_CREATED: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onCreateView called!
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onActivityCreated called!
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): key=android:view_state
    10-19 00:59:58.489: V/FragmentManager(7837): movefrom ACTIVITY_CREATED: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroyView called! view=android.support.v4.app.NoSaveStateFrameLayout@42853930
    10-19 00:59:58.489: V/FragmentManager(7837): movefrom CREATED: DetailFragment{42633190 #0 id=0x1020002}
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDestroy called!
    10-19 00:59:58.489: V/FragmentLifeTimeTest Log:(7837): DetailFragment.onDetach called!
    10-19 00:59:58.489: V/FragmentManager(7837): Freeing fragment index DetailFragment{42633190 #0 id=0x1020002}
     
       
  • 相关阅读:
    设计模式之《工厂方法》
    设计模式之 《简单工厂》
    fegin 调用源码分析
    ajax上传预览
    ajax小应用
    ajax执行流程1
    ajax异步post方法
    ajax get异步方法
    js ajax请求流程
    form表单提交
  • 原文地址:https://www.cnblogs.com/manziluo/p/5800390.html
Copyright © 2020-2023  润新知