示例#1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
      dataBase = new DataBaseHelper(getApplicationContext());
    } catch (Exception e) {
      deleteDatabase(DataBaseHelper.DATABASE_NAME); // delete DataBase
    }

    // Check that the activity is using the layout version with
    // the fragment_container FrameLayout
    if (findViewById(R.id.fragment) != null) {
      if (savedInstanceState != null) {
        return;
      }
      // Create a new Fragment to be placed in the activity layout
      menuFragment = new MenuFragment();

      // In case this activity was started with special instructions from an
      // Intent, pass the Intent's extras to the fragment as arguments
      menuFragment.setArguments(getIntent().getExtras());

      // Add the fragment to the 'fragment_container' FrameLayout
      getSupportFragmentManager().beginTransaction().add(R.id.fragment, menuFragment).commit();
    }

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
      isAppLoadingAsLandScape = true;
    // Orientation must be PORTRAIT while app loading
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }