MrRobot9
MrRobot9

Reputation: 2684

Caching listview items when the user is offline

I am using Marvel api to get name, images and description, but I want the users to view it in offline mode too...How can I cache it apart from db system? Can Lru cache be used to do it? I just want to know the approach

Upvotes: 1

Views: 299

Answers (1)

Hitesh Sahu
Hitesh Sahu

Reputation: 45072

Store your marvel arrayList to db with the help of TinyDB in ACtivity onPause() CallaBack

ArrayList<Person> usersWhoWon = new ArrayList<Person>();
tinydb.putListObject("allWinners", usersWhoWon);

and then in onResume() callaback check if user is offline and fetch your marvel comic list from tinyDB

new TinyDB(getApplicationContext()).getListObject(
                    PreferenceHelper.MY_CART_LIST_LOCAL, Marvel.class)

Upvotes: 1

Related Questions