# Android landscape mode game

I am beginner in android game development. I want my game to run only in landscape fullscreen mode (currently I have Optimus 2X with resolution 800x480 in landscape), and I don't know how to set it.

I found the fullscreen mode settings, and tried some landscape mod (set orientation:landscape in AndroidManifest), but the game is now crashing and its very unstable (eg. when i change phone orientation).

So is there any way to do that?

• Code does help. – The Communist Duck Jul 1 '11 at 11:06
• What part of my code should I post? My problem is how to set landscape in simple android app, because I cant find anythink in android development docs. – davidv Jul 1 '11 at 11:18
• Post your LogCat error message. – Wroclai Jul 2 '11 at 16:52

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

<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);

...
}


If you have more than one activity that you are using, you are going to need to set the orientation for all of them to landscape, if you have one as landscape and another as portrait. When you switch over to the other activity it will crash unless you have it set up properly to do that. If I knew how to post the code from my manifest to where it shows up I would.

The link explains if you want to switch between orientations.
http://developer.android.com/resources/articles/faster-screen-orientation-change.html