Code example for FragmentManager

Methods: beginTransactionfindFragmentById

0
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
 
    //TODO before calling fragment, to get ID and give that to it. 
    FragmentManager fm = getSupportFragmentManager();
    if(fm.findFragmentById(android.R.id.content) == null){
      searchFrag = new RegularSearchFragment();
      fm.beginTransaction().add(android.R.id.content, searchFrag).commit();
    } 
  } 
 
  protected void onNewIntent(Intent intent){
    Log.d(TAG, "In on new intent");
    if(Intent.ACTION_SEARCH.equals(intent.getAction())){
      String searchQuery = intent.getStringExtra(SearchManager.QUERY);
      searchQuery = searchQuery.trim();
      getIntent().putExtra(SearchManager.QUERY, searchQuery);
      getSupportLoaderManager().restartLoader( 
        SearchFragment.LIB_SEARCH_LOADER_TAG, null, searchFrag);
    } 
  }