屏幕方向和manifest.xml的价值观价值观、屏幕、manifest、方向和

2023-09-06 09:46:16 作者:悔之晚矣

我想用所有的活动在我的形式,横向或纵向。 当用户选择的方向 - 这是适用于所有的活动。 试图与落后的选择方向。据谷歌 - 方向将依赖于previous活动。 我的第一个活动中使用setRequestedOrientation来设置从用户定位选择。 接下来的活动必须遵循相同的方向。 我必须把setRequestedOrientation在他们的code吗?或者relly在manifet'背后'参数?把setRequestedOrientation可能导致的onCreate了吗?

I want to use all activities in my form in landscape or portrait. When user select orientation - this is valid for all activities. Tried with "behind" option orientation. According to Google - orientation will depend on previous activity. My first activity use setRequestedOrientation to set selected from user orientation. Next activities have to follow same orientation. Do I have to put setRequestedOrientation in their code too? Or relly on 'behind' parameter in manifet? Putting setRequestedOrientation may be cause onCreate again?

更新: 尝试肖像和setRequestedOrientation() - resilt SI的onCreate被称为2倍。 问题是下一个活动 - >因为在第一个活动肖像的 - 开始Android的下一个活动具有相同的方向。它忽略了山水的方向至极被我设置:(

UPDATE: Tried "portrait" and setRequestedOrientation() - resilt si onCreate was called 2 times. Problem is in next activity -> because of "portrait" in first activity - android started next activity with same orientation. It ignores "landscape" orientation wich was set by me :(

推荐答案

现在我就把检查的onCreate:

For now I put check in onCreate:

m_bSkip = (this.getRequestedOrientation() != MyApp.sInstance.GetScreenOrientation());
if (m_bSkip)
  return;

当我输入的OnCreate和屏幕方向是不希望 - 退出。 当我的onCreate输入和屏幕方向所需要的一个 - 继续初始化。 这修复情况,而不需要保持异步任务有关的活动,并检查是否有新的活动。 当然,所有的功能:ONSTART,onResume,onPausde,的onStop ......要检查这个标志,以避免空指针异常

When I enter oncreate and screen orientation is not desired - exit. When I enter in onCreate and screen orientation is desired one - continue with initialization. This fixes situation without need of keeping async task related to activity and check for new activity. Of course all functions: onStart,onResume,onPausde,onStop... have to check this flag to avoid null pointer exception.