In my Activity I have a lateinit
property called controller
that my Fragment uses.
This property is initialized in Activity.onCreate()
. My Fragment
gets its reference back to my Activity
through onAttach()
. The Fragment
then calls myActivity.controller
in Fragment.onCreate()
.
Normally controller
is first initialized in Activity.onCreate()
, and after that, the Fragment
is added. So this works just fine.
But when my Activity
has been killed, it tries to recreate itself and its fragments. This causes Fragment.onCreate()
to be called before the initialization took place in Activity.onCreate()
.
These are the options I see right now:
- initialize
controller
beforesuper.onCreate()
(if that's even possible) - move the call to
myActivity.controller
to a later lifecycle callback, asonViewCreated()
- something with
::controller.isInitialized
available in Kotlin 1.2
What is my best option here?