Open markzyu opened 8 years ago
Need to better handle view lifecycle events.
I am thinking about using Provider rather than directly injecting (in the latter way the pointer will not change even if activity has been stopped and restarted.)
On Sunday, February 14, 2016, lafickens notifications@github.com wrote:
Need to better handle view lifecycle events.
— Reply to this email directly or view it on GitHub https://github.com/TakefiveInteractive/Ledger-Android/issues/9#issuecomment-184032009 .
I concur. Realm instances should always be retrieved from providers and closed in lifecycle events when appropriate.
I just looked it up and actually it was a re-creation rather than re-starting, and that's why the code in onCreate is called again and accessed Realm. BTW, when shall we close the Realm connection? Do we create our Activity base class to do that?
Reference: http://developer.android.com/training/basics/activity-lifecycle/recreating.html#SaveState
On Sunday, February 14, 2016, lafickens notifications@github.com wrote:
I concur. Realm instances should always be retrieved from providers and closed in lifecycle events when appropriate.
— Reply to this email directly or view it on GitHub https://github.com/TakefiveInteractive/Ledger-Android/issues/9#issuecomment-184033048 .
If we were to make a base activity, then it only makes sense to use on single realm within a single activity (and casting to the base class type perhaps?) . That can be tricky to manage sometimes. I would suggest calling Realm.close()
in onPause
and somehow reopen realm in onResume
. Currently I only have realm closed in onDestroy
.
This bug can be reproduced (but not related to changes brought) in commit 114a1721a1605d3a115b36e95a18c3bfd30bc2a5, by changing the device orientation while browsing MainActivity.