0

我有我的 android 应用程序,点击即可打开统一播放器。我的统一播放器按预期执行。

问题:在更改屏幕旋转时,应用程序崩溃。

调试控制台输出:

I/Unity: StopVuforia

         (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
D/AR: RenderManager: Could not retrieve a valid GLSurfaceView in view hierarchy, therefore cannot set any render mode
W/MessageQueue: Handler (android.os.Handler) {90dbee5} sending message to a Handler on a dead thread
                java.lang.IllegalStateException: Handler (android.os.Handler) {90dbee5} sending message to a Handler on a dead thread
                    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
                    at android.os.Handler.enqueueMessage(Handler.java:643)
                    at android.os.Handler.sendMessageAtTime(Handler.java:612)
                    at android.os.Handler.sendMessageDelayed(Handler.java:582)
                    at android.os.Handler.sendMessage(Handler.java:519)
                    at android.os.Message.sendToTarget(Message.java:416)
                    at com.unity3d.player.UnityPlayer$e.a(Unknown Source)
                    at com.unity3d.player.UnityPlayer$e.b(Unknown Source)
                    at com.unity3d.player.UnityPlayer.b(Unknown Source)
                    at com.unity3d.player.UnityPlayer.a(Unknown Source)
                    at com.unity3d.player.UnityPlayer.a(Unknown Source)
                    at com.unity3d.player.UnityPlayer$17.surfaceDestroyed(Unknown Source)
                    at android.view.SurfaceView.updateWindow(SurfaceView.java:588)
                    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:247)
                    at android.view.View.dispatchDetachedFromWindow(View.java:15567)
                    at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4914)
                    at android.view.ViewGroup.removeAllViews(ViewGroup.java:4860)
                    at com.unity3d.player.UnityPlayer.quit(Unknown Source)
                    at com.Accenture.Activity.UnityPlayerActivity.onDestroy(UnityPlayerActivity.java:66)
                    at android.app.Activity.performDestroy(Activity.java:6889)
                    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1175)
                    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4231)
                    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4262)
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4536)
                    at android.app.ActivityThread.-wrap19(ActivityThread.java)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:154)
                    at android.app.ActivityThread.main(ActivityThread.java:6165)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
W/MessageQueue: Handler (android.os.Handler) {90dbee5} sending message to a Handler on a dead thread
                java.lang.IllegalStateException: Handler (android.os.Handler) {90dbee5} sending message to a Handler on a dead thread
                    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
                    at android.os.Handler.enqueueMessage(Handler.java:643)
                    at android.os.Handler.sendMessageAtTime(Handler.java:612)
                    at android.os.Handler.sendMessageDelayed(Handler.java:582)
                    at android.os.Handler.sendMessage(Handler.java:519)
                    at android.os.Message.sendToTarget(Message.java:416)
                    at com.unity3d.player.UnityPlayer$e.b(Unknown Source)
                    at com.unity3d.player.UnityPlayer.b(Unknown Source)
                    at com.unity3d.player.UnityPlayer.a(Unknown Source)
                    at com.unity3d.player.UnityPlayer.a(Unknown Source)
                    at com.unity3d.player.UnityPlayer$17.surfaceDestroyed(Unknown Source)
                    at android.view.SurfaceView.updateWindow(SurfaceView.java:588)
                    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:247)
                    at android.view.View.dispatchDetachedFromWindow(View.java:15567)
                    at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4914)
                    at android.view.ViewGroup.removeAllViews(ViewGroup.java:4860)
                    at com.unity3d.player.UnityPlayer.quit(Unknown Source)
                    at com.Accenture.Activity.UnityPlayerActivity.onDestroy(UnityPlayerActivity.java:66)
                    at android.app.Activity.performDestroy(Activity.java:6889)
                    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1175)
                    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4231)
                    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4262)
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4536)
                    at android.app.ActivityThread.-wrap19(ActivityThread.java)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:154)
                    at android.app.ActivityThread.main(ActivityThread.java:6165)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
W/Unity: Timeout while trying detaching primary window.

AndroidManifest

<activity
            android:name=".UnityPlayerActivity"
            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="landscape"
            android:theme="@style/UnityThemeSelector">
            <meta-data
                android:name="unityplayer.UnityActivity"
                android:value="true" />
        </activity>

解决方法:

“修复屏幕更改应用程序崩溃”或“强制横向视图”将使我的解决方案。

  1. 我尝试将统一播放器设置更改为横向左侧。
  2. 我试过orientation|layoutDirection|screenLayout从 android 清单文件中删除我的。
  3. 我试过添加screenOrientation="landscape/user/nosensor/fulluser"
4

1 回答 1

0

我在更改方向时搜索了很多 Unity Player 崩溃,但没有找到有用的解决方案。

因此,由于这是我的可行性,我将我的方向锁定为“风景”模式。

为了这,

第 1 步:Unity 播放器设置

转到编辑 > 项目设置 > 播放器,它将在检查器中打开播放器设置。

从列表中选择目标平台。

单击“分辨率和演示文稿”部分。

将默认方向设置为横向左/右。

请参阅此博客:https ://answers.unity.com/questions/774186/landscape-mode-only.html

第 2 步:Android 代码更改。

在清单文件中,

<activity
            android:name=".UnityPlayerActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="landscape"
            android:theme="@style/UnityThemeSelector">
            <meta-data
                android:name="unityplayer.UnityActivity"
                android:value="true" />
</activity>

此外,还要以编程方式进行定向。

private int screenOrientation;
// lock screen orientation to landscape mode only.
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
setRequestedOrientation(screenOrientation);
于 2018-06-11T06:57:48.840 回答