You can use the HTTP HEAD method to check the date of the change on the server and see if you really need to receive new data. Each time the application starts and at intervals during its operation, it requests a server to see if the data has changed. This assumes that the data is cached on the server, and not dynamically generated on every request or depending on which client makes the request.
Thus, you need to save the data and date for each item. SharedPreferences should be sufficient if the data is a string of moderate length, and its amount is only a few kilobytes. If there is a known upper bound on the length of the data, then use the database, otherwise you could use simple files. SharedPreferences writes an xml file every time you commit.
You can create a Thread with a long wait interval to perform periodic checks, or create a handler and use postDelayed or the like to create a non-reversible thread. Check items as often as possible for outdated data. If you check every 10 minutes, you get up to 10 minute data, on average half of which. A check at startup will make things appear up to date in most cases anyway.
If all the items expire at once, you only need to check the date of one item to know that they should all be updated. If not, you can try using a conditional GET instead of checking the HEAD of each element.
source share