hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
431 stars 49 forks source link

Crash Navigator Not Init #158

Closed chrisjenx closed 3 years ago

chrisjenx commented 3 years ago

Testing locally I can't reproduce, so I'm guessing a real world issue where the Fragment isn't started before I call navigate from the TurboActivity?

This is where we get a deeplink which passes a location into the turbo activity. We use lifecycle hooks to fire this, so should always be fire on or after on activity onCreate

Caused by kotlin.UninitializedPropertyAccessException
lateinit property navigator has not been initialized
dev.hotwire.turbo.delegates.TurboFragmentDelegate.getNavigator$turbo_release (Unknown Source:6)
dev.hotwire.turbo.nav.TurboNavDestination$DefaultImpls.getNavigator (Unknown Source:4)
dev.hotwire.turbo.nav.TurboNavDestination$DefaultImpls.navigate (Unknown Source:10)
dev.hotwire.turbo.fragments.TurboFragment.navigate (Unknown Source:10)
dev.hotwire.turbo.nav.TurboNavDestination$DefaultImpls.navigate$default (Unknown Source:28)
dev.hotwire.turbo.delegates.TurboActivityDelegate.navigate (Unknown Source:23)
dev.hotwire.turbo.delegates.TurboActivityDelegate.navigate$default (Unknown Source:20)
com.zaarly.MainTurboActivity.handleDeeplinks (MainTurboActivity.kt:54)
com.zaarly.MainTurboActivity.access$handleDeeplinks (MainTurboActivity.kt:22)
com.zaarly.MainTurboActivity$lifecycleObserver$1.onCreate (MainTurboActivity.kt:63)
androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged (FullLifecycleObserverAdapter.java:36)
androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent (LifecycleRegistry.java:361)
androidx.lifecycle.LifecycleRegistry.forwardPass (LifecycleRegistry.java:300)
androidx.lifecycle.LifecycleRegistry.sync (LifecycleRegistry.java:339)
androidx.lifecycle.LifecycleRegistry.moveToState (LifecycleRegistry.java:145)
androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent (LifecycleRegistry.java:131)
androidx.lifecycle.ReportFragment.dispatch (ReportFragment.java:68)
androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostCreated (ReportFragment.java:170)
android.app.Activity.dispatchActivityPostCreated (Activity.java:1242)
android.app.Activity.performCreate (Activity.java:7972)
android.app.Activity.performCreate (Activity.java:7952)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3629)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3806)
android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:83)
android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2267)
android.os.Handler.dispatchMessage (Handler.java:107)
android.os.Looper.loop (Looper.java:237)
android.app.ActivityThread.main (ActivityThread.java:8167)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:496)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)
jayohms commented 3 years ago

@chrisjenx I recommend following the approach I outlined here:

https://github.com/hotwired/turbo-android/issues/142#issuecomment-772585629

Activity.onCreate() is too early to navigate, since the NavHostFragment may not be attached/ready.

chrisjenx commented 3 years ago

Closing in favor of: https://github.com/hotwired/turbo-android/issues/142#issuecomment-772585629