Question

I'm quite new in Java android development. So I have an issue with my app.

I was build a android app with phoneGap opensource and Jquery mobile framework. That's looking good normally working.

But the issue is.... when I'm trying to rotate the phone after running the app, then unexpectedly the app is closing.

It's not only for my phone it's happening on every android phone.

I really want to remove the screen rotation on the app.

Hope you understand

Help me please....

Was it helpful?

Solution

I had probably the same issue - crash on rotate. I dont think I had the AndroidManifest.xml copied right from the tutorial. I didnt add

 android:configChanges="orientation|keyboardHidden" 

to the 1st activity. See my after and before:

After (working):

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".App"
        android:label="@string/app_name"  android:configChanges="orientation|keyboardHidden">
        <intent-filter>

Before (crash on rotate):

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".App"
        android:label="@string/app_name">
        <intent-filter>

Not sure if you really want to fix the screen or stop it crashing but if you want to fix portrait or landscape you can do this:

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".App"
        android:label="@string/app_name"  android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="landscape" >
        <intent-filter>

OTHER TIPS

You have to use the following js in your main page.

$(document).ready(function() {
    var canDetect = "onorientationchange" in window;
    var orientationTimer = 0;

    var ROTATION_CLASSES = {
        "0": "none",
        "90": "right",
        "-90": "left",
        "180": "flipped"
    };

    $(window).bind(canDetect ? "orientationchange" : "resize", function(evt) {
        clearTimeout(orientationTimer);
        orientationTimer = setTimeout(function() {
            // display the event type and window details
            $("#event-type").html(evt.type);
            $("#window-orientation").html(window.orientation);
            $("#window-width").html(window.innerWidth);
            $("#window-height").html(window.innerHeight);

            // given we can only really rely on width and height at this stage, 
            // calculate the orientation based on aspect ratio
            var aspectRatio = 1;
            if (window.innerHeight !== 0) {
                aspectRatio = window.innerWidth / window.innerHeight;
            } // if

            // determine the orientation based on aspect ratio
            var orientation = aspectRatio <= 1 ? "portrait" : "landscape";

            // if the event type is an orientation change event, we can rely on
            // the orientation angle
            var rotationText = null;
            if (evt.type == "orientationchange") {
                rotationText = ROTATION_CLASSES[window.orientation.toString()];
            } // if

            $(window).trigger("reorient", [orientation, rotationText]);
        }, 500);
    });

    $(window).bind("reorient", function(evt, orientation, rotation) {
        // display the details we have determine from the display
        $("#orientation").html(orientation);
        $("#rotation-class").html(rotation);
    });
});

That works for me without doing anything in the manifest.xml

I had the same problem. I was developing PhoneGap application with android:minSdkVersion="8" and android:targetSdkVersion="16". When I tried to add screenSize to android:configChanges it says that screenSize does not exist. Then I reduced the targetSdkVersion and everything starts working perfectly. This is my manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
  package="com.planetclub.mobile" android:versionName="1.1" android:versionCode="6">
<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:resizeable="true"
    android:anyDensity="true"
    />
<uses-permission android:name="android.permission.INTERNET" />   
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

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

I think your problem has nothing to do with any specific framework; most likely you reference some invalid instance. Bear in mind that an orientation change causes the system to go through the process of saving instance state, pausing, stopping, destroying, and then creating a new instance of the activity with the saved state. So if you - for example, save a reference to some instance, then after an orientation change the reference is not valid any more (probably null).

You should try to fix it, check this reference. But if you really don't want to allow screen orientation changes, then add following property to your main activity in the manifest file:

android:screenOrientation="portrait/landscape"
android:configChanges="keyboardHidden|orientation|screenSize">

If you are developing for Android API 13 or higher you need to add screenSize to android:configChanges in order to prevent a crash. Like this:

android:configChanges="orientation|screenSize|keyboardHidden"

Found this here:

https://groups.google.com/forum/?fromgroups#!msg/phonegap/HYUfLJF1oH0/r9rZTfz_cccJ

I ran though the same problem. The app died when I moved from portrait to landscape or landscape to portrait. No reason.

I checked the android:configChanges="orientation|keyboardHidden" and added the screensize but no change.
I made so many changes. I finally cancelled the line and rewrote it and it worked.
I think the line had a problem not seen by the Eclipse editor and not visible. The original line was a copy/paste from the phonegap installation.

I met the same problem. But my android:configChanges was set correctly. In the end I found that I need to change the miniSdkVersion from 15 to 7.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top