1

我是 Java android 开发的新手。所以我的应用程序有问题。

我正在使用 phoneGap 开源和 Jquery 移动框架构建一个 android 应用程序。正常工作看起来不错。

但问题是......当我在运行应用程序后尝试旋转手机时,意外地应用程序正在关闭。

这不仅适用于我的手机,它也发生在每部安卓手机上。

我真的想删除应用程序上的屏幕旋转。

希望你能理解

请帮帮我....

4

7 回答 7

10

我可能有同样的问题 - 旋转时崩溃。我认为我没有直接从教程中复制 AndroidManifest.xml。我没加

 android:configChanges="orientation|keyboardHidden" 

到第一个活动。看我的前后:

之后(工作):

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

之前(旋转时崩溃):

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

不确定您是否真的想修复屏幕或阻止它崩溃,但如果您想修复纵向或横向,您可以这样做:

    <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>
于 2012-03-05T13:18:38.893 回答
4

您必须在主页中使用以下 js。

$(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);
    });
});

这对我有用,无需在 manifest.xml 中做任何事情

于 2012-08-04T19:00:09.230 回答
3

我有同样的问题。android:minSdkVersion="8"我正在使用和开发 PhoneGap 应用程序android:targetSdkVersion="16"。当我试图添加它时,screenSize它说不存在。然后我减少了,一切都开始完美运行。这是我的清单文件android:configChangesscreenSizetargetSdkVersion

<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"/>

于 2012-12-06T21:05:52.100 回答
1

我认为您的问题与任何特定框架无关;很可能您引用了一些无效的实例。请记住,方向更改会导致系统经历保存实例状态、暂停、停止、销毁,然后创建具有保存状态的活动的新实例的过程。因此,如果您 - 例如,保存对某个实例的引用,则在方向更改后,该引用不再有效(可能为空)。

您应该尝试修复它,检查此参考。但是,如果您真的不想允许屏幕方向更改,请在清单文件中的主要活动中添加以下属性:

android:screenOrientation="portrait/landscape"
android:configChanges="keyboardHidden|orientation|screenSize">
于 2012-01-19T23:11:29.787 回答
1

如果您正在为 Android API 13 或更高版本进行开发,则需要将 screenSize 添加到 android:configChanges 以防止崩溃。像这样:

android:configChanges="orientation|screenSize|keyboardHidden"

在这里找到这个:

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

于 2012-05-29T17:43:47.623 回答
1

我遇到了同样的问题。当我从纵向转到横向或从横向转到纵向时,该应用程序就死了。没理由。

我检查android:configChanges="orientation|keyboardHidden"并添加了屏幕尺寸但没有变化。
我做了很多改变。我终于取消了这条线并重写了它,它奏效了。
我认为该行存在 Eclipse 编辑器未发现且不可见的问题。原始行是 phonegap 安装的复制/粘贴。

于 2012-06-01T15:27:38.077 回答
0

我遇到了同样的问题。但我的 android:configChanges 设置正确。最后我发现我需要将 miniSdkVersion 从 15 更改为 7。

于 2012-08-04T07:47:30.380 回答