When I learned the P124 page of the Android Programming Authority Guide, I ran into this code:
Cause my question if the judging condition is (fragment==null), that executes the last sentence fragment Fragment=fm.findfragmentbyid (R.id.fragmentcontainer); What exactly is the value of fragment? Through debug, I found that actually executed Fragment Fragment=fm.findfragmentbyid (r.id.fragmentcontainer), Fragment value is null, why is this? Refer to Google's official documentation of this method, there are two words: Finds A fragment that is identified by the given ID either when inflated from XML or as the contain Er ID when added in a transaction. .......... Returns:the fragment if found or null otherwise. (because we did not define the fragment in the activity layout XML file, and did not add fragment with Fragmentmanager, so this method is not found the corresponding fragment, the return value is naturally null)
Discussion on the return value of method Findfragmentbyid (int id) in fragment