why using android:configChanges is a bad practice

后端 未结 3 2135
眼角桃花
眼角桃花 2021-02-19 21:23

I have gone through different posts and questions for handling rotation and AsyncTask. In each post it is mentioned that using android:configChanges is

3条回答
  •  隐瞒了意图╮
    2021-02-19 21:48

    Well, you need to remember that an Activity can be restarted for multiple reasons.

    For example, one of these reasons is when your app is in the background and the OS decides to kill it (with your Activity, of course) to reclaim memory.

    When you return to your app, the OS will try to recreate your Activity as you left it, but will fail to do so, because you decided not to bother with it, just used android:configChanges in your Manifest.

    If you make sure your app can recover properly from a restart, android:configChanges might not be necessary at all. Because of this, the need to use android:configChanges might indicate some flaw in your app, that may worth to take a look at.

    It's not bad practice to use android:configChanges, but it pretty easily can be, if you don't understand exactly what you're doing.

提交回复
热议问题