-
- Downloads
Fix landscape view induced MainActivity leak.
With landscape view enabled (e.g. e06b2c7d) in the app and auto rotation enabled on the phone, switching between portrait and landscape orientations leaks instances of MainActivity. This prevents garbage collection of not just the MainActivity object, but fragments and other objects referenced by the Activity. This is caused by repositories, the AppContext instance, the player service, and authentication code maintaining a reference to the context which with they are initialized. So rather than initialize these with an Activity context, pass them the Application context. Activities are torn down and rebuilt on screen rotation. The Application context is not. To enable instantiation of the FavoritedRepository with the Application context, delay that repository’s initialization until first use. This ensures the Application context is fully initialized. It is not fully initialized until the MainActivity has been fully initialized.