调用上一个 Activity 的 onStop 后,相机方向恢复为默认值
我对我的 Android 应用程序有疑问。 在我的主要活动中,即活动 B,我在 onResume() 中将相机方向设置为与显示屏相同。 在进入活动 B 之前,我有另一个活动(活动 A),看起来相机方向回到了默认方向,它调用活动 A 的 onStop()
以下是流程:
Activity A onCreate()
Activity A onResume()
Activity A onPause()
Activity B onCreate()
Activity B onResume()
set mCamera.setDisplayOrientation(result);
----> set properly, i can see the good orientation about 1-2 ms.
Activity A onStop()
----> camera orientation goes to default.
----> If i didn't do anything here, device will sleep, once i wake up, i can get the camera orientation i want
Activity B onPause() --> due to device sleep
Activity B onResume() ---> because I turn on back device
set mCamera.setDisplayOrientation(result);
---> camera orientation is good now
我的问题是 “如何设置以使前一个活动的 onStop() 不会将方向更改回默认值?”
我在活动 B 的清单文件中添加了 android:alwaysRetainTaskState="true",但它不起作用,
提前致谢。
I have a question for my android application.
In my main activity, said activity B, I setup camera orientation to be the same as the display, at onResume().
Before it goes to activity B, i have another activity (said activity A), and it looks like the camera orientation goes back to the default one it call activity A's onStop()
Here is the flow:
Activity A onCreate()
Activity A onResume()
Activity A onPause()
Activity B onCreate()
Activity B onResume()
set mCamera.setDisplayOrientation(result);
----> set properly, i can see the good orientation about 1-2 ms.
Activity A onStop()
----> camera orientation goes to default.
----> If i didn't do anything here, device will sleep, once i wake up, i can get the camera orientation i want
Activity B onPause() --> due to device sleep
Activity B onResume() ---> because I turn on back device
set mCamera.setDisplayOrientation(result);
---> camera orientation is good now
My question is
"How to setup so the previous activity's onStop() will not change the orientation back to default?"
I added android:alwaysRetainTaskState="true" at manifest file for my activity B, but it's not working
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置方向后,在 Activity B 中的 sharedPreferences 中保留一个布尔值。错误可能意味着一种方向,正确可能意味着另一种方向。然后您可以检查 Activity B 的 onResume 中的布尔值。这种方式可以让您保持应用程序中的活动之间的方向或清除内存中的数据。
注意:您可以将任何原始数据和字符串保存在sharedPreferences中。我只是选择布尔值,因为你只需要保存 2 个状态。
Persist a boolean in sharedPreferences in Activity B after the orientation is set. False can mean one orientation and true can mean another. Then you can check the boolean in onResume of Activity B. This way will let you persist the the orientation between the activities in the app or data getting cleaned out of memory.
Note: You can save the any primitive data and Strings in sharedPreferences. I just chose boolean because you only needed to save 2 states.