hotwired / turbo-android

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

Navigating to a different Activity with ReplaceRoot #143

Closed chrisjenx closed 8 months ago

chrisjenx commented 3 years ago

When you navigate to a different activity using the internal navigation + replace_root, it doens't finish the activity you are coming from. Again not sure if thats correct or not, but my understanding of replace_root is like "NEWTASK/CLEARTASK"? Or at least that screen should be the start of the stack.

This most common when say LoginActivity -> MainTurboActivity when we have logged in and out states divided by an activity scope. And Visa versa, MainTurboActivity -> LoginActivity.

Thanks, Chris

chrisjenx commented 3 years ago

I can of course override the shouldNavigate, but something tells me that replace_root should replace activities too, Or maybe adding another explicit clear_stack? or something?

jayohms commented 3 years ago

Yeah, you're correct, navigating to an Activity currently doesn't respect the presentation flags - sorry, that isn't documented anywhere at the moment. Currently, in that situation we simply do the following:

LoginActivity:

private fun navigateToMainActivity() {
    delegate.navigate(urls.activityMainUrl)
    finish()
}

I can see how this is problematic, though, if you're using a web login flow in your LoginActivity. We use an all-native login flow, so we hadn't directly hit the issue where you need to finish() an Activity during web navigation.

I haven't put much thought into presentation flags for activities yet, simply because the primary use case is Fragment navigation and navigating between activities should be infrequently used. I agree that this could be a lot nicer - especially considering that the presentation flags can be changed remotely to change behavior without an app update.

I'll think about this a bit more and figure out what makes sense. A limited subset, or separate presentation flags for activities might be best.

chrisjenx commented 3 years ago

yeah, I just added finish() on calling navigate(login) so no rush from over here. Just something to think about I guess. :+1: