I'm currently working on a full-screen Android game that runs exclusively in landscape mode. Here are the tweaks I've made to force landscape mode and prevent application restarts:
Intercept orientation change events
Add the following android:configChanges to your AndroidManifest.xml
<activity android:name=".FirstGame"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
Override onConfigurationChanged in your Activity to prevent application restart
@Override
public void onConfigurationChanged(final Configuration newConfig)
{
// Ignore orientation change to keep activity from restarting
super.onConfigurationChanged(newConfig);
}
Forcing full-screen landscape orientation
In the onCreate function of your Activity, add the following code to set window fullscreen and remove title bar, and force landscape orientation
import android.view.Window;
import android.view.WindowManager;
import android.content.pm.ActivityInfo;
@Override public void onCreate(Bundle savedInstanceState)
{
...
// Set window fullscreen and remove title bar, and force landscape orientation
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
...
}