Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap app crashes when switched orientation even with AndroidManifest changes

Here's my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mappp.mobile"
    android:versionCode="1"
    android:versionName="1.0" >
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
    />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <uses-permission android:name="android.hardware.camera" />
    <uses-permission android:name="android.hardware.camera.autofocus" />
    <uses-sdk android:minSdkVersion="13" /> 

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:debuggable="true" 
        android:configChanges="orientation|screenSize|keyboardHidden"  >
        <activity
            android:label="@string/app_name"
            android:name=".MAppHDActivity" >
             <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="com.phonegap.DroidGap" 
            android:label="@string/app_name" 
            android:configChanges="orientation|screenSize|keyboardHidden" > 
            <intent-filter>
            </intent-filter>
        </activity>
    </application>

</manifest>

I'm using Phonegap 1.3.0 and jquerymobile.

My test device is a Samsung Galaxy Tab 8.9 with HC v3.2.

I've read ALMOST every forum with the same issue. It still fails when i rotate the screen.

There's a warning right after the app crashes in debug mode: webcore: Can't get the veiwWidth after the first layout.

like image 338
Martin Ongtangco Avatar asked Jan 28 '12 14:01

Martin Ongtangco


2 Answers

In your case the attribute android:configChanges="orientation|screenSize|keyboardHidden" should go to the first <activity> tag and not the <application> tag.

For the other people having similar issues simply add screenSize to android:configChanges="orientation|keyboardHidden" or change the android:minSdkVersion attribute to 12 or lower.

A more detailed explanation of this behavior can be found here: http://groups.google.com/group/phonegap/msg/c771fffc4dd9daaf

like image 112
Daniel P Avatar answered Oct 31 '22 18:10

Daniel P


Here's my solution Add "screenSize" to the android:configChanges in each Activity tag (within the AnroidManifest.xml).

Like this:

android:configChanges="orientation|screenSize|keyboardHidden"

It solved my problem.

like image 3
Huzoor Bux Avatar answered Oct 31 '22 18:10

Huzoor Bux