Firestore+LiveData+ViewModel(?)+Singleton = Good idea?

178 views
Skip to first unread message

Bernardo Ferrari

unread,
Jan 2, 2018, 4:10:16 PM1/2/18
to Firebase Google Group

Hi!


I have an app (as you can see in the screenshot attached) with multiple screens having a shared data. On iOS, I put the data fetched from Firebase in multiple hashmaps and send then (as reference) to other screens. If someone modifies something, everything is kept up to date, both local and on server.

On Android.. well.. I thought about using multiple global LiveDatas inside an object/singleton, but became a nightmare. Since it is not synchronised, one activity instance might make the call observe(...), which will call Firebase, but if I, very fast, close and reopen the activity with another value, it might receive the value from before instead of the one it should get and things get chaotic. I'm not sure what I should do, if I put ViewHolders in the middle, it will probably solve this problem, but won't I restrict the global liveDatas to local and loose the benefits I want? All examples I found from everywhere, from Medium to Firebase Blog deal with local values and a single activity, not a full app.

Could someone help me on this one?






38988.jpg
Reply all
Reply to author
Forward
0 new messages