混合Android应用程序中的方向问题

时间:2014-04-29 11:21:46

标签: android

请帮助我解决这个问题..我正在混合Android移动应用程序工作..它工作正常,但当我改变方向时,应用程序重新启动....在纵向和横向......

这是我的清单文件:

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


 <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="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:allowBackup="true"
    android:icon="@drawable/icon_dropin"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <activity
        android:name="com.cogzidel.dropinn.MainActivity"
        android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="sensor">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

这是我的主要活动:

@覆盖

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      super.setIntegerProperty("splashscreen",R.drawable.loading_img);
      super.init();
      if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            fixJellyBeanIssues();
        }

      super.loadUrl("file:///android_asset/www/index.html",8000);  

}


 public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }

@TargetApi(16)
protected void fixJellyBeanIssues() {
    System.out.println(super.appView.toString());
    try {
        super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    } catch(NullPointerException e) {
        System.out.println(e.toString());
    }
}

// catch an error and if try again 1x or quit
@Override
public void onReceivedError( int errorCode, String description, String failingUrl)
{
    if(retryCount < 3) {
        retryCount++;
        System.out.println("Connection failed, trying again. Retry Count: "+retryCount);
        super.loadUrl("file:///android_asset/www/listspace.html");
    } else {
        System.out.println("Sorry, it failed three times so I give up.");
        super.loadUrl("file:///android_asset/www/fail.html");
    }
    return;
}

}

1 个答案:

答案 0 :(得分:0)

如果不希望您的应用程序重新启动,您必须在Android清单中明确声明这样

<activity android:name=".MyActivity"
      android:configChanges="orientation"
      android:label="@string/app_name">

然而,不建议这样做,并将其视为最后的手段。 在这里,您可以了解更多应如何处理配置更改 http://developer.android.com/guide/topics/resources/runtime-changes.html