In my activity, I have a lateinit property called controller that uses my Fragment. This property is initialized in Activity.onCreate() . My Fragment returns a link to my Activity via onAttach() . Fragment then calls myActivity.controller in Fragment.onCreate() .
Normally, the controller initialized in Activity.onCreate() , after which Fragment added. So it works great.
But when my Activity was killed, it tries to recreate itself and its fragments. This causes Fragment.onCreate() to call before initialization in Activity.onCreate() .
These are the options that I see right now:
- initialize
controller to super.onCreate() (if possible) - move the call to
myActivity.controller to the subsequent lifecycle callback, like onViewCreated() - something with
::controller.isInitialized available in Kotlin 1.2
What is my best option here?
source share