Code example for FragmentActivity

Methods: getActionBar, getIntent, getSupportFragmentManager, onCreate, setTitle

0
    public static final int FRAGMENT_CUSTOM_LAYOUT = 2;
 
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(getIntent().getStringExtra(EXTRA_TITLE));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true); 
        } 
        // Check what fragment is shown, replace if needed. 
        Fragment fragment = getSupportFragmentManager().findFragmentById(android.R.id.content);
        if (fragment == null) {
            // Make new fragment to show. 
            int fragmentId = getIntent().getIntExtra(EXTRA_FRAGMENT, FRAGMENT_DEFAULT);
            switch (fragmentId) {
                case FRAGMENT_DEFAULT:
                    fragment = DefaultProgressFragment.newInstance();
                    break; 
                case FRAGMENT_EMPTY_CONTENT:
                    fragment = EmptyContentProgressFragment.newInstance();
                    break; 
                case FRAGMENT_CUSTOM_LAYOUT:
                    fragment = CustomLayoutProgressFragment.newInstance();
                    break; 
                default: 
                    fragment = DefaultProgressFragment.newInstance();
                    break; 
 
            } 
            getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
        } 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {