r/androiddev • • Sep 11 '26

Discussion Preloading remote data before navigation

I don't understand why there isn't a clear, native way to delay navigating (either between activities or between navigation3 destinations) while also being able to initialize the necessary data. What I mean is this: I would like to be able to start an activity but not show the animation transtion, just start its lifecycle. There I would instantiate the ViewModel and do the call for the necessary data. Once the data are ready I would like to inform the previous activity and then show the animation.
Also in case I need to know if the call succeeded in order to "transition" to the next screen this could help me keep the two activities completely independent in logic. I just navigate from activity A to B and in case it's needed I handle a result too. That's it. Otherwise I would need to add the dependency in A for B's call and data and then I would also have to either pass them which could be stupid in cases or cache them to a singleton repo which could be a bad idea too.

0 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/deckerjeffreyr Sep 13 '26

You said in your original post that singleton repositories can be a bad idea so that was a bit confusing. But it sounds like your team is overlooking the point of repositories with appropriate scope.

Either way I'm not sure what you win by showing loading on screen A instead of B. If that's really what you want then you can pass the data when it's loaded as a part of the intent but this typically isn't suggested because the bundle has a size limit. This is why a shared repository is usually the answer for going between activities.

It sounds like you need to make a call between a less than ideal solution, a requirements adjustment, or a conversation with your team about the value of repositories.

1

u/Tough-Geologist8613 Sep 13 '26

I understand everything you are saying and the decision for showing the loading in screen A comes from the designer team, not me. But can you at least see the value in what I'm suggesting?