N
N
newdancer2020-06-19 10:14:51
Android
newdancer, 2020-06-19 10:14:51

How to deal in Kotlin when activity returns null?

Who can tell in the splash screen fragment in onActivityCreated I call

Handler().postDelayed({
            navigateToDestination(R.id.action_splashFragment_to_startFragment)
        }, 2000L)

the method itself looks like this
fun navigateToDestination(@IdRes destination: Int, args: Bundle? = null, navOptions: NavOptions? = null) {
        (activity as NavigationActivity).navigateToDestination(destination, args, navOptions)
    }


But on some devices I get a fatal Exception error: kotlin.TypeCastException null cannot be cast to non-null type in the line (activity as NavigationActivity).navigateToDestination(destination, args, navOptions)
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question