@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = new TestView(this); setContentView(view); // new World(new Vec2(0.0f, -10.0f), true); gravity = getPreferences(Context.MODE_PRIVATE).getInt(PREF_GRAVITY, GRAVITY_ACCELEROMETER); w = (PhysicsWorld) getLastNonConfigurationInstance(); if (w == null) { Vec2 grav = new Vec2(0.0f, 0.0f); if (gravity == GRAVITY_NORMAL) { grav.y = -10.0f; } else if (gravity == GRAVITY_MOON) { grav.y = -1.67f; } w = new PhysicsWorld(); w.create(grav); } view.setModel(w); if (savedInstanceState != null) { defaultLandscape = savedInstanceState.getBoolean(KEY_DEFAULT_LANDSCAPE); } else { defaultLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; rotation = getPreferences(Context.MODE_PRIVATE).getInt(PREF_ROTATION, Surface.ROTATION_0); int orientation; if (defaultLandscape && rotation == Surface.ROTATION_90 || !defaultLandscape && rotation == Surface.ROTATION_180) { orientation = 9; } else if (defaultLandscape && rotation == Surface.ROTATION_180 || !defaultLandscape && rotation == Surface.ROTATION_270) { orientation = 8; } else if (defaultLandscape && rotation == Surface.ROTATION_270 || !defaultLandscape && rotation == Surface.ROTATION_0) { orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else { orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } setRequestedOrientation(orientation); } }