Problems when handling orientation changes

后端 未结 3 919
刺人心
刺人心 2020-12-19 11:35

I need to handle orientation changes in my Android application. For this purpose I decided to use OrientationEventListener convenience class. But his callback m

相关标签:
3条回答
  • 2020-12-19 11:52

    This is a documented bug in the emulator ONLY. A real device will not exhibit this double-lifecycle-events behavior. I had the same issue a while ago and it disappears on a real device.

    I would suggest ignoring the problem if you can by only testing orientation changes in one direction until you get your hands on a physical phone. Otherwise you might be able to "skip" the second set of lifecycle calls by keeping a static boolean around indicating you've already gone through the first set.

    See this issue report for more info.

    0 讨论(0)
  • 2020-12-19 12:02

    Have you tried using onConfigurationChanged?

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
     if(newConfig.equals(Configuration.ORIENTATION_LANDSCAPE)…
    
    0 讨论(0)
  • 2020-12-19 12:06

    Add android:configChanges="orientation" in manifest file in activity tag like

    <activity android:label="@string/app_name" android:configChanges="orientation" android:name=".com.androidpeople">

    0 讨论(0)
提交回复
热议问题