Each time the new SDK creates an activity, it automatically generates
<pre name= "code" class= "Java" >public static class Placeholderfragment extends Fragment
Fragment module, the nested fragment code on the basis of the module is as follows:
<pre name= "code" class= "Java" >public static class Placeholderfragment extends Fragment {static Fragmentmanager FM; Public placeholderfragment () { fm=getchildfragmentmanager ();} @Override public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); } @Overridepublic View Oncreateview (Layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {view Rootview=layoutinflater.from (Getactivity ()). Inflate (R.layout.tab, NULL), if (Fm.findfragmentbytag ("haha") ==null) { Fragment1 f1=new Fragment1 (); Fm.begintransaction (). Add (r.id.frame_tab,f1, "haha"). commit ();} return Rootview;}
The resulting error is as follows:
In short it means that acitivity was destroyed.
Reason:
Fm=getchildfragmentmanager (); in <span style= "font-family:arial, Helvetica, Sans-serif;" Called in the >placeholderfragment constructor, when it has not yet created a oncreate, it naturally gets less than fragment and activity, so writes it to </span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ></span><pre name= "code" class= "java" ><pre name= "code" class= "java" >public void OnCreate (Bundle Savedinstancestate) { super.oncreate (savedinstancestate); Fm=getchildfragmentmanager (); }
Error resolution, we must pay attention to the fragment and activity life cycle.