aman.nepid
aman.nepid

Reputation: 3054

How to avoid force close on mobile phone orientation change?

my android application crashes and shows force close when i tilt the mobile phone. is there any suggestions that i can remove such problem? By the way i am developing a LBS application which uses the google maps (MapView).

I have a splash screen and then shown a ListActivity as below :

<activity android:name=".Splash" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Home" android:label="@string/app_name" android:configChanges="orientation" android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="com.nepways.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>


what is wrong with my declaration, the splash screen loads and list activity is also whown correctly but when i change the orientation the application is closed. Please help me.

Upvotes: 0

Views: 1899

Answers (3)

sebap123
sebap123

Reputation: 2685

First of all as it is said the app is restarting (or as it is said in reference redrawing) each time when you change orientation. To block it in your manifest file in activity you have to put this line which describes the activity orientation:

    <activity android:name=".Splash" 
android:label="@string/app_name"
android:screenOrientation="portrait">...

And about this buttons, or keymaps. Telling the truth Ive got thise warnings sometimes but it doesnt change anything in my app. So first change the orientation settings and then it should work correct.

If you want use other screen orientation remember to check here: http://developer.android.com/guide/topics/manifest/activity-element.html

Upvotes: 2

plus-
plus-

Reputation: 46543

When you change your orientation the activity is restarted

  1. look at the logcat to see what exception causes your application to FC
  2. You can change your manifest to disable activity restarting by customizing configChanges, if you stil have the problem override onConfigurationChanged() to fix what is generating this exception (like initialize something that may cause a nullpointer)

Upvotes: 3

nhaarman
nhaarman

Reputation: 100448

If you want to avoid restarting your activity on orientation change, you can put this in the activity in the manifest file:

android:configChanges="orientation"

Otherwise, we will need to see more code, and a stacktrace.

Upvotes: 0

Related Questions