Kotlin How to share between 2 different activitiy's 2 different fragments

28 views Asked by At

I'm trying to improve myself on kotlin but i have issues, like in the title i want to share data between 2 different activity's 2 different fragments but with livedata i cannot observe data from other activity's fragment; on MainActivity i have bottombar, in bottombar i have homefragment, cartfragment and userfragment; in homefragment im getting products from api and listing them by gridlayout when i clicked one of them i'm opening 2nd activity's fragment and it showing up product detail then inside of this screen i have "add to basket button" when i clicked this button i want to do add product to cartfragment's gridlayout, with livedata i can not do that, how can i sent this data? for now i fixed this issue by using sharedpreferences with sharedpreferences i'm saving product's slug from productdetailfragment (which im getting products details) to sharedpreferences then on cartfragment getting data from sharedprefernces and using @GET method to get productdetails and add to basket. (some people said you can use DataStore but i did not use it before and do not know everything on compose verywell, btw i can not push data to API because it's not letting me API is not mine)

Tried LiveData and tried sharing data with Navigation but i have bottombar so it's getting bugged. I putted ProductDetails to bottombar but i made it invisible when i try to navigate and share data with navigation it's getting bugged.

0

There are 0 answers