I have created a View Model :
class ShareUserVM : ViewModel() {
lateinit var previousPath: UserPreviousPath
}
enum class UserPreviousPath {
SIGN_IN,
SIGN_UP,
PROFILE
}
I am initializing this lateinit variable in Profile Fragment,SignIN Fragment and SignUp Fragment before going to EnterUserDetails Fragment In EnterUserDetails.kt :
class EnterUserDetails {
.
.
.
private val sharedUserVM: ShareUserVM by activityViewModels()
.
.
.
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?) :View {
.
.
.
shouldAuthenticate = sharedUserVM.previousPath == UserPreviousPath.PROFILE
.
.
.
}
So when I am opening EnterUserDetailsFragment.kt, it is opening fine and but when I open another app on my phone and come back to this app after around 5-10 mins this app crashes saying kotlin.UninitializedPropertyAccessException: 'lateinit property previousPath has not been initialized'