Code example for FragmentManager

Methods: beginTransactionfindFragmentById

0
  @Override 
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
 
    FragmentManager fm = getSupportFragmentManager();
    if(fm.findFragmentById(android.R.id.content) == null){
      searchFrag = new RandomSearchFragment();
      fm.beginTransaction().add(android.R.id.content, searchFrag).commit();
    } 
  } 
} 
Contextual code suggestions in your IDE  Get Codota for Java