简体   繁体   中英

How to retrieve data from a database efficiently?

I'm building an android app, and I need to retrieve a list of users from a database. I know how to write the query. I will have back a list of object.

I was wondering how to do this in an efficient way considering that I need that list in 3 activities. I think that repeating the same code for 3 times, in 3 different activities is not optimal.

Thanks

As per you comment you are fetching this user data from server, you can consider following:

  1. make a web service to retrieve user list.
  2. call the web service first time you need list of users.
  3. cache this list in shared preferences or SQLite DB, depending upon size of list.
  4. use it where ever you need.
  5. refresh your list from server periodically or as per your need.

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