问题描述
我的申请涉及到音乐,我使用的是Android 4.2.2。我已经在我的每个活动指定以下行锁定我的应用程序为横向模式:
的android:screenOrientation =风景
现在,当我把我的音乐应用程序在横向模式下打开,锁与钥匙的设备的屏幕,在纵向模式旋转设备,然后解锁设备的屏幕会导致我的音乐应用程序抛出异常。
我试过多种解决方案,就像在我的清单设置configChanges
的android:configChanges =keyboardHidden |方向|屏幕尺寸
但没有什么似乎工作。我在这里张贴异常的堆栈跟踪。请帮我这个问题。
注意:保持在横向模式下的音乐应用程序,锁定设备和解锁它会做什么应用程序。应用的工作原理像以前一样,还显示了被锁定装置打开前的活动。
我想要做什么:我要锁定我的应用程序(只是我的应用程序,而不是整个设备)为横向模式,并在同一时间不听的任何方向变化设备。
谢谢!
堆栈跟踪:
E / AndroidRuntime(17468):致命异常:主要
E / AndroidRuntime(17468):了java.lang.RuntimeException:无法启动活动ComponentInfo com.android.music / com.android.music.MediaPlaybackActivity}:显示java.lang.NullPointerException
E / AndroidRuntime(17468):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E / AndroidRuntime(17468):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E / AndroidRuntime(17468):在android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
E / AndroidRuntime(17468):在android.app.ActivityThread.access $ 700(ActivityThread.java:141)
E / AndroidRuntime(17468):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1240)
E / AndroidRuntime(17468):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(17468):在android.os.Looper.loop(Looper.java:137)
E / AndroidRuntime(17468):在android.app.ActivityThread.main(ActivityThread.java:5041)
E / AndroidRuntime(17468):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(17468):在java.lang.reflect.Method.invoke(Method.java:511)
E / AndroidRuntime(17468):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
E / AndroidRuntime(17468):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E / AndroidRuntime(17468):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(17468):显示java.lang.NullPointerException:产生的原因
E / AndroidRuntime(17468):在com.android.music.MediaPlaybackActivity.onCreate(MediaPlaybackActivity.java:232)
E / AndroidRuntime(17468):在android.app.Activity.performCreate(Activity.java:5104)
E / AndroidRuntime(17468):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E / AndroidRuntime(17468):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E / AndroidRuntime(17468):... 12多
可能是别人有同样的问题有帮助。
所以,以下线的工作(虽然它不是一个很好的解决方案来处理这种类型的变化)
的android:configCganges =方向/屏幕尺寸
因为我没有把它提供活动的名称之后它没有为我工作了。因此,如果它不是一个正确的顺序,它不会工作。 (至少为Android 4.2.2)
例如,下面code ++工程。
<活动
机器人:名字=com.android.music.MediaPlaybackActivity
机器人:configChanges =方向|屏幕尺寸
机器人:screenOrientation =风景
机器人:出口=真正的>
My application is related to Music and I am using Android 4.2.2. I have locked my application to landscape mode by specifying below line in each of my activity:
android:screenOrientation="landscape"
Now, when I keep my Music application open in landscape mode, lock the screen of the device with the keys, rotate the device in portrait mode and then unlock the screen of the device will cause my Music application throw an Exception.
I tried multiple solution like setting the configChanges in my manifest
android:configChanges="keyboardHidden|orientation|screenSize"
But nothing seem to work. I am posting the stack trace of the exception here. Please help me with this issue.
Note : Keeping the music application in landscape mode, locking the device and unlocking it will do nothing to the application. App works like before and also displays the activity which was opened before locking the device.
What I want to do: I want to lock my application (just my app and not the whole device) to landscape mode and at the same time don't listen to any orientation change of the device.
Thanks!
Stacktrace:
E/AndroidRuntime(17468): FATAL EXCEPTION: main
E/AndroidRuntime(17468): java.lang.RuntimeException: Unable to start activity ComponentInfo com.android.music/com.android.music.MediaPlaybackActivity}: java.lang.NullPointerException
E/AndroidRuntime(17468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime(17468): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(17468): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
E/AndroidRuntime(17468): at android.app.ActivityThread.access$700(ActivityThread.java:141)
E/AndroidRuntime(17468): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
E/AndroidRuntime(17468): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17468): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(17468): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(17468): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17468): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(17468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(17468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(17468): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(17468): Caused by: java.lang.NullPointerException
E/AndroidRuntime(17468): at com.android.music.MediaPlaybackActivity.onCreate(MediaPlaybackActivity.java:232)
E/AndroidRuntime(17468): at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime(17468): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime(17468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime(17468): ... 12 more
Might be helpful for someone else having the same problem..
So, Below line works (Though it is not a very good solution to handle this type of changes)
android:configCganges="orientation/screenSize"
It did not work for me before because I did not put it right after providing the activity's name. So it will not work if it is not in a proper order. (At least for Android 4.2.2)
For example, Below code works.
<activity
android:name="com.android.music.MediaPlaybackActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="landscape"
android:exported="true" >
这篇关于Android应用方向锁定为横向,锁定装置,它旋转到纵向和解锁,应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!