Hello everyone I always wonder whats the best way ...
# android-architecture
r
Hello everyone I always wonder whats the best way to share between 2 different screens in android. For eg: Im creating a record in create page + create view model. From there, Im inserting list of subform data for which im invoking Subform page. Once subform data are filled, I need to transport this list data from subform screen to create screen, where I will show them as table. Also, some data like org, user data from API needed to be available throughout all the screens. So what's the best way to do this ? Shared VM/DB caching/Hit server api in all screens or any other way ?!
c
have no idea what you've talking about. but basically the way to "share" data between screens is to put it in a place thats accessible by both screens. Options: 1. put the data in the application class/singleton/process level scoped class 2. Put it in a shared VM 3. Put it in some shared storage (database or data store/sharedPrefs/some file) 4. put it in the cloud/backend As a "last" ish resort you could pass things around with intent extras/navigation extras etc. idk seems dumb to serialize things in your own app to move them around. you own the app code. just put it somewhere you can access it. if you need it in two different spots... then maybe it should legitimately be application scoped data instead of just living on the screen.
👍 2
a
Usual way is through local db, sort of single source of truth. But yeah, depends on what you are doing.
👍 1
r
Thanks guys!