Restarting or recreating an activity with dagger issue
Opened this issue · 1 comments
mkodekar commented
For example
@Module(includes = arrayOf(SharePrefsModule::class))
class NavigatorModule {
@Provides
@OriggonScope
fun provideNavigator(preferences: SharedPreferences): Navigator {
if (preferences.getString(Utils.CRID, "").isEmpty()) {
return Navigator.withRoot(LoginScreen()).loggingEnabled(true).build()
} else {
val screenList = ArrayList<Screen<*>>()
screenList.apply {
add(MainScreen())
add(LikesScreen())
add(HistoryScreen())
}
return Navigator.withRoot(BaseScreen(screenList)).loggingEnabled(true).build()
}
}
}
and the navigator.onCreate() on the injecting activity
and finally when i want to restart an activity after clearing sharedpreference , i might want to go to the loginscreen instead of the basescreen, the normal way without dependency injection works flawlessly where as the dependency injection method launches the Basescreen again.
fabiendevos commented
The usual way to handle that use case is to simply use rewriteHistory()
in your Activity's onCreate
.
Also you need to make sure that your Navigator is basically a Singleton (or at least a Singleton within your scope), and that it does not go away when the activity get's rotated.
On can simply use @singleton and only have one Navigator for the whole app for example.