我正在开发一个平板电脑应用程序。一切正常,直到设备被锁定。一旦设备被锁定并旋转,就会出现强制关闭。
我强迫我的应用程序仅在横向模式下运行。所以我在清单中提到了这个权限。
<activity
android:name=".activity.LoginActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
因此,当我锁定我的设备并使其旋转时,方向会发生变化,并且会产生这种力关闭。
为了解决这个问题,我在清单中添加了这个权限。
android:configChanges="orientation"
在代码中:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.i("Log", "Configuration changes called");
int orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// or = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
setRequestedOrientation(orientation);
}
我还在onCreate()中添加了这一行
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Log", "OnCreate");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.lyt_login_main);
........
}
但它仍然没有得到解决。请帮我解决这个问题。
这是我得到的错误:
12-17 11:13:57.877: E/AndroidRuntime(10462): FATAL EXCEPTION: main
12-17 11:13:57.877: E/AndroidRuntime(10462): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marico.icp/com.marico.icp.activity.LoginActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000f
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3365)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.access$700(ActivityThread.java:128)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1165)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.os.Looper.loop(Looper.java:137)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.main(ActivityThread.java:4514)
12-17 11:13:57.877: E/AndroidRuntime(10462): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 11:13:57.877: E/AndroidRuntime(10462): at java.lang.reflect.Method.invoke(Method.java:511)
12-17 11:13:57.877: E/AndroidRuntime(10462): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-17 11:13:57.877: E/AndroidRuntime(10462): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
12-17 11:13:57.877: E/AndroidRuntime(10462): at dalvik.system.NativeStart.main(Native Method)
12-17 11:13:57.877: E/AndroidRuntime(10462): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03000f
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.content.res.Resources.getValue(Resources.java:1037)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2144)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.content.res.Resources.getLayout(Resources.java:870)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-17 11:13:57.877: E/AndroidRuntime(10462): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.Activity.setContentView(Activity.java:1835)
12-17 11:13:57.877: E/AndroidRuntime(10462): at com.marico.icp.activity.LoginActivity.onCreate(LoginActivity.java:77)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.Activity.performCreate(Activity.java:4465)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
12-17 11:13:57.877: E/AndroidRuntime(10462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
12-17 11:13:57.877: E/AndroidRuntime(10462): ... 12 more
提前致谢。