I am using the Volley library to pull data from a remote db.
I have locked the fetching process inside a ProgressDialog because, if not, I noticed the data could or could not reach the app. By locking it, I make sure the data is there to be shown to the users.
Now, I have implemented a local db so the user doesn't need to fetch from the remote db the same information every time.
The information fetched, only comes when a certain condition is met. This is the SQL:
SELECT *
FROM user_meals
WHERE CURDATE() BETWEEN date_of_meal AND DATE_ADD(date_of_meal, INTERVAL 14 DAY)
AND email = '$email'
ORDER BY date_of_meal DESC
LIMIT 1
The process goes like: Android app sends petition to PHP file -> PHP file runs SQL -> PHP file answers -> Android app listens to the answer.
So my question is:
How can I make the fetching process run in the background, and make it run every given amount of time?
Thank you.
Edit:
Apparently it is a bad practice to do periodic requests to a server. So instead, I am going to handle them on demand. Thank you all.