Borislav Nesterov
Jul 27, 2017 · 1 min read

Great article and great approach!
(in fact, I came up with something similar on my own :)

I have a question about the first point, where you say

“You shouldn’t be fighting the lifecycle of each component. If the Fragment/Activity gets destroyed then you should just save any important data on the respective callbacks (like saving a document as backup).”

Let’s say you have an app with MainActivity that has a nav drawer with 2 sections: “News Feed” and “Messages”.

Each section is a Fragment that’s shown inside the activity.

When you go to another section, one Fragment replaces another,

so a Fragment that’s being replaced is completely destroyed (Fragment stack has only one Fragment at a time).

Say you’re scrolling the News Feed and want to quickly switch to Messages, and then go back to the same scroll position in the News Feed.

How do you save and restore the scroll position?

(If your ViewModel is destroyed with the Fragment, the only option is to save scroll position in DB/SharedPreferences/etc. Which is not very fast or pretty)