2022/04 3

SaveInstanceState가 생긴 이유

출처 : https://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html 이전 포스팅에서 적었지만 InstanceState로 인하여 IllegalStateException  발생한다. 근데 이게 왜 필요한가? 안드로이드 플랫폼에서 상태를 자동으로 샤샥 저장해 주면 되잖아?? 물론 그렇다. 하지만 현실적인 문제가 있다. 폰의 메모리는 한정적이기 때문에 모두 저장해 주지 못한다. 거기다 플랫폼에서 메모리가 없으면 앱을 죽여 버리기 까지 한다.. 이것에 대한 해결책으로 안드로이드가 제시한 것은, 이전 상태의 정보를 저장하고 앱을 재 실행할 때 복원해 주는 것이다. 그럴듯하고 실제로도 잘 동작한다. 다만 개발자가 ..

Fragment 전환 시 IllegalStateException 원인 및 해결

출처 : https://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html https://proandroiddev.com/kotlin-extensions-to-commit-fragments-safely-de06218a1f4 https://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit 원인 Activity의 onSaveInstanceState()가 호출된 후에 FragmentTransaction의 commit()을 동작하는 데에 있습니다. 이건 안드로이드..