1

私はJavaAndroid開発にまったく慣れていません。そのため、アプリに問題があります。

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

私も同じ問題を抱えていました。とを使用してPhoneGapアプリケーションを開発しandroid:minSdkVersion="8"ていandroid:targetSdkVersion="16"ました。私がそれに追加しようとしたときscreenSize、それは存在しないandroid:configChangesと言います。screenSizeそれから私は減らしました、targetSdkVersionそしてすべてが完全に働き始めます。これは私のマニフェストファイルです

<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

あなたの問題は特定のフレームワークとは何の関係もないと思います。ほとんどの場合、無効なインスタンスを参照しています。向きを変更すると、システムはインスタンスの状態を保存し、一時停止、停止、破棄してから、保存された状態でアクティビティの新しいインスタンスを作成するプロセスを実行することに注意してください。したがって、たとえば、あるインスタンスへの参照を保存すると、方向を変更した後、その参照は無効になります(おそらくnull)。

あなたはそれを修正しようとするべきです、この参照をチェックしてください。ただし、画面の向きの変更を本当に許可したくない場合は、マニフェストファイルのメインアクティビティに次のプロパティを追加します。

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

Android API 13以降用に開発している場合は、クラッシュを防ぐためにandroid:configChangesにscreenSizeを追加する必要があります。このような:

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 に答える