Code example for FragmentActivity

Methods: getSupportFragmentManager, finish, getClassLoader, getIntent, onCreate, requestWindowFeature, setRequestedOrientation

0
	 
	private Fragment mBaseFragment;
	 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		 
		Intent launchIntent = getIntent();
		final String fragclassname = launchIntent.getStringExtra(EXTRA_FRAGMENTNAME);
		final Bundle fragargs = launchIntent.getBundleExtra(EXTRA_FRAGMENTARGS);
		final int orient = launchIntent.getIntExtra(EXTRA_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		setRequestedOrientation(orient);
		 
		try { 
			Class<?> fragmentClass = getClassLoader().loadClass(fragclassname);
			mBaseFragment = (Fragment) fragmentClass.newInstance();
			mBaseFragment.setArguments(fragargs);
			 
			FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
			tr.add(android.R.id.content, mBaseFragment);
			tr.commit();
			 
		} catch(Exception e) {
			Log.e(FragmentShellActivity.class.getName(), "", e);
			finish(); 
		} 
		 
	} 
	 
	public static Intent createIntent(Context context, Class<?> fragmentClass, Bundle fragmentArgs){
Stop searching for code, let great code find you!  Add Codota to your java IDE