简体   繁体   中英

retrofit fetching data from local storage in android studio

I need to save last api results in my app if the user open the app without network connection, then he will see last data fethed from the server, i need to fetch json as string and parse json to objects from string by using retrofit library in android studio

Refer about: https://medium.com/@prabuddafernando_53470/mvvm-architecture-viewmodel-and-livedata-f28c0d20300b

what you can do is check the internet on repository, it not connected fetch the data from local share preference, if its too much data use room persistence database for the data saving. in the repository can call two way of option 1. Is from remote repository 2. is from remote repository. hence you can get the data from local repo if the internet is not available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM