app crash when screen orientation changes???

14,846 views
Skip to first unread message

mr.xXx

unread,
Dec 12, 2011, 9:39:52 PM12/12/11
to phonegap
Somebody please help me..
recently i just develop android app using phonegap and jquery mobile..
After I changes the orientaion of the enumerator, the app crash.
I already search many place for solution, but still not solve the
problem.

Gaurav dixit

unread,
Dec 13, 2011, 5:21:08 AM12/13/11
to phon...@googlegroups.com
could you please elaborate your problem.if you don't want to change orientation then fix it in android manifest.

thanks
Gaurav Dixit


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

ingsolv

unread,
Dec 15, 2011, 10:31:58 AM12/15/11
to phonegap
I had the same problem, setting minSdkVersion to 2 in
AndroidManifest.xml fixed it for me.

<uses-sdk android:minSdkVersion="2" />

icache

unread,
Dec 23, 2011, 10:21:57 PM12/23/11
to phonegap
Setting minSdkVersion to 2 also worked for me - but that is not a
solution I can live with.

So I did some more testing. In my AndroidManifest.xml the
android:screenOrientation="landscape"
was in a second activity tag, below an activity tag that also included
an intent-filter section that
contained intent.action.MAIN & intent.category.LAUNCHER actions. I
moved the
android:screenOrientation="landscape" out of that second activity tag
to the first activity
tag (so it would be declared before the two action intents) That
worked! I then went back and
changed minSdkVersion back to 8 and it still worked! No crash, screen
maintains the
orientation I set.

Eclipse AndroidManifest>Application>Application Nodes>.~Activity &
com.phonegap.DroidGap both have
settings for orientation and both insert it into the second activity
tag after the
intent.action.MAIN & intent.category.LAUNCHER. Perhaps that is wrong -
at least from
my experience.

Justin S

unread,
Dec 25, 2011, 11:28:55 PM12/25/11
to phon...@googlegroups.com
First, thank you mr.xXx for posting this issue and thank you everyone else for your replies. I stumbled upon this thread trying to solve the same problem.

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" 



And here's the reasoning
Looking through the Android docs, I found this page:

Towards the bottom of the page, there's a cautionary-note:
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). 

That means that, if you are working with anything API level 13 or above, you need to add "screenSize" to PhoneGap's traditional recommendation of "orientation" and "keyboardHidden" in the android:configChanges.

So each activity tag should have
       android:configChanges="orientation|screenSize|keyboardHidden"

...like so:

<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
             android:configChanges="orientation|screenSize|keyboardHidden">
        <intent-filter>
        </intent-filter>
</activity>

Lowering the minSdkVersion below 13 works because Android no longer restarts the application based on a screenSize configuration change.

Simon MacDonald

unread,
Jun 16, 2012, 7:50:15 PM6/16/12
to phon...@googlegroups.com

Run "adb logcat" so we can see what the root cause of the problem is.

Simon

On Jun 16, 2012 7:04 PM, "Adam" <adamm...@gmail.com> wrote:
I'm still getting this crash with phonegap 1.8.1, a 2.3 phone, and a 2.2 simulator.

My manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.yourgroup.yourname"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:resizeable="true"
    android:anyDensity="true" />
<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.permission.BROADCAST_STICKY" />
   
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HelloCordovaActivity"

            android:label="@string/app_name" >
            android:configChanges="orientation|screenSize|keyboardHidden"         
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Adam

unread,
Jun 17, 2012, 12:50:06 PM6/17/12
to phon...@googlegroups.com
Logcat from the time I hit Run in Eclipse until I change orientation and crash:

06-17 11:45:34.507: D/DroidGap(6469): Origin to allow: http://127.0.0.1*
06-17 11:45:34.507: I/CordovaLog(6469): Found log level DEBUG
06-17 11:45:34.507: I/CordovaLog(6469): Changing log level to DEBUG(3)
06-17 11:45:34.507: I/CordovaLog(6469): Found preference for classicRender
06-17 11:45:34.507: D/DroidGap(6469): DroidGap.onCreate()
06-17 11:45:34.507: D/DroidGap(6469): DroidGap.loadUrl(file:///android_asset/www/index2.html)
06-17 11:45:34.507: D/DroidGap(6469): DroidGap: url=file:///android_asset/www/index2.html baseUrl=file:///android_asset/www/
06-17 11:45:34.517: D/DroidGap(6469): DroidGap.init()
06-17 11:45:34.537: D/PluginManager(6469): init()
06-17 11:45:34.557: D/SoftKeyboardDetect(6469): Ignore this event
06-17 11:45:34.557: D/szipinf(6469): Initializing inflate state
06-17 11:45:34.557: D/szipinf(6469): Initializing zlib to inflate
06-17 11:45:34.587: D/SoftKeyboardDetect(6469): Ignore this event
06-17 11:45:34.787: I/Database(6469): sqlite returned: error code = 14, msg = cannot open file at line 27205 of [42537b6056]
06-17 11:45:34.917: D/dalvikvm(6469): GC_CONCURRENT freed 412K, 49% free 3148K/6087K, external 380K/542K, paused 2ms+2ms
06-17 11:45:37.817: D/DroidGap(6469): Origin to allow: http://127.0.0.1*
06-17 11:45:37.817: I/CordovaLog(6469): Found log level DEBUG
06-17 11:45:37.817: I/CordovaLog(6469): Changing log level to DEBUG(3)
06-17 11:45:37.817: I/CordovaLog(6469): Found preference for classicRender
06-17 11:45:37.817: D/DroidGap(6469): DroidGap.onCreate()
06-17 11:45:37.817: D/DroidGap(6469): DroidGap.loadUrl(file:///android_asset/www/index2.html)
06-17 11:45:37.817: D/DroidGap(6469): DroidGap: url=file:///android_asset/www/index2.html baseUrl=file:///android_asset/www/
06-17 11:45:37.817: D/DroidGap(6469): DroidGap.init()
06-17 11:45:37.827: I/Database(6469): sqlite returned: error code = 14, msg = cannot open file at line 27205 of [42537b6056]
06-17 11:45:37.837: D/PluginManager(6469): init()
06-17 11:45:37.857: D/SoftKeyboardDetect(6469): Ignore this event
06-17 11:45:37.857: D/szipinf(6469): Initializing inflate state
06-17 11:45:37.857: D/szipinf(6469): Initializing zlib to inflate
06-17 11:45:38.027: D/CordovaLog(6469): exception firing pause event from native
06-17 11:45:38.027: D/CordovaLog(6469): : Line 1153648881 : exception firing pause event from native
06-17 11:45:38.027: I/Web Console(6469): exception firing pause event from native at :1153648881
06-17 11:45:38.117: W/IInputConnectionWrapper(6469): showStatusIcon on inactive InputConnection
06-17 11:46:05.787: D/dalvikvm(6469): GC_EXPLICIT freed 309K, 49% free 3116K/6087K, external 380K/542K, paused 67ms

Simon MacDonald

unread,
Jun 18, 2012, 9:52:32 AM6/18/12
to phon...@googlegroups.com
I went back and re-read your manifest. It looks like the XML is not
valid. You have:

<activity
android:name=".HelloCordovaActivity"

android:label="@string/app_name" >
android:configChanges="orientation|screenSize|keyboardHidden"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

when it should be:

<activity
android:name=".HelloCordovaActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

The config changes attribute has to be inside the activity tag.
Simon Mac Donald
http://hi.im/simonmacdonald

Adam

unread,
Jun 18, 2012, 12:08:32 PM6/18/12
to phon...@googlegroups.com
That seems to fix it! Thanks!

Simon MacDonald

unread,
May 31, 2013, 2:58:54 PM5/31/13
to phonegap
Make sure that your config changes are:

    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"

Your SDK line should be something like:

    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="17"/>

If Eclipse is still giving you a red x on the line for config changes, right click on the project and close it. Then double click it to open and it should go away.

On Fri, May 31, 2013 at 1:15 PM, Dwight Fowler <dwight...@gmail.com> wrote:
I am having exactly the same issue as Alberto. I have a minSdkVersion=10 targetSdkVerison=17. I've added PhoneGap's recommendation configChanges="orientation|screen|keyboardHidden"

When I try to add "screenSize" I get an error message saying it is not a valid value. 
I'm developing on Eclipse Juno Java EE for Web Developers.

My app restarts when the orientation changes.

I'm running the app on a Nexus 7 Android 4.2.2 and a Droid X Android 2.3.4. They both show the same behavior.

Can anyone shed some light on what is going on?




On Monday, January 21, 2013 6:37:30 AM UTC-8, Alberto De Boni wrote:
I've got a similar issue and googling for days lead me to nowhere.
I've added the lines said in this thread but the application still restar as soon as screen rotate.
First issue i've found is that screenSize is not allowed, looking at possible tags i've found screeLayout... but it doesn't work either.


I've got a page with authentication (index.html) that uses jQuery changePage to show main Application page on authentication success..

        //console.log('Content'+content);
        window.plugins.Base64ToString.convert(content, {},
                function(result) {
                    decodedContent = result;
                    console.log('Decoded' + decodedContent);
                    if (decodedContent.length > 0) {
                        var x = $(decodedContent);
                        myUserSID = x.attr('user_sid');
                        console.log('UserSID' + myUserSID);
                        var store = window.sessionStorage.setItem("UserSID", myUserSID);
                        $.mobile.changePage('mainPage.html');
                    } else {
                        // TODO not logged alert.

                    }
                    ;
                }, function(error) {
            alert(error);
        });

},

on main page a screen rotation lead to go back to authentication page.

Here's the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
          package="wtnet.wtnet" android:versionName="1.1" android:versionCode="5" >
    <supports-screens

        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.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>

    <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.permission.BROADCAST_STICKY" />


    <application android:icon="@drawable/icon" android:label="@string/app_name"
                 android:debuggable="true"
                 android:allowBackup="false">
        <activity android:name="WTNET" android:label="@string/app_name" android:configChanges="orientation|screenLayout|keyboardHidden"
                  android:theme="@android:style/Theme.Black.NoTitleBar" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
</manifest>

Any help?


On Wednesday, September 19, 2012 9:31:36 PM UTC+2, Fred Stluka wrote:
Same typo here.  Thanks!

You'd think after using XML extensively for 12+ years, I would have avoided such a simple typo.  Oops!

BTW, it's worth noting that not only is it UNECESSARY to add screenSize when using API level less than 13, but also it is INCORRECT to add it in that case.  Before API level 13, the screenSize value was not valid as part of android:configChanges, and causes this error at compile time:
     String types not allowed (at 'configChanges' with value  'orientation|keyboardHidden|keyboard|screenSize|locale').

--Fred Stluka

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dwight Fowler

unread,
May 31, 2013, 11:19:33 PM5/31/13
to phon...@googlegroups.com
Simon,
Thanks for your help. It was the trigger that helped me to finally track down the cause of the problem. The invalid "screenSize" was the important clue. I've encountered this kind of error before. My project was targeted at Android 2.3.3. Here's how I was finally able to fix this:
  1. Set the "android:minSdkVersion" property in your AndroidManifest.xml to the oldest version of Android you are targeting your application at (for me it was 10, i.e. Android v2.3.3).
  2. In the Eclipse "Package Explorer", right-click on the project.
  3. In the pop-up context menu, select "Properties". The properties dialog opens.
  4. Select "Android" in the left side panel. The right side of the dialog will display "Project Build Target"
  5. Pick a version of "Android" or "Google API" that is greater than 13 or 14. (I'm not sure which one has the fix). I used 17.
  6. Click the "Apply" button.
  7. Click the "Ok" button.
  8. Very Important : Clean the project. Go to the Eclipse main menu: Project > Clean...
  9. Make sure that your PhoneGap project is selected.
    1.  use either "Clean all projects" or "Clean projects selected below"
    2. Click the "Ok" button.
  10. Build and deploy your app on your oldest targeted device.
That solved my problem. 

Carlos Iván

unread,
Sep 23, 2014, 6:38:59 PM9/23/14
to phon...@googlegroups.com
Thank's a lot. My App runing in the perfect.
Regards. Friend.
Reply all
Reply to author
Forward
0 new messages