Android background process loading data from webpage every minute

I’m working on an Android app with a constant repeating background process.

From the moment the device starts it should load data off a webpage every minute. It uses XmlPullParser and a simple URL inputstream. It is but 10kb so it isn’t that intensive. I believe this kind of task is called Deferred. The information loaded by the process has to be accessible to the Activity once that the user opens the app. The background process also needs to be abled to place a notification once the data shows certain results.

There seem to be multiple methods to achieve this in Android, eg. a JobScheduler, WorkManager or AlarmManager however everything I’ve tried so far seems to either stop once the activity closes or doesn’t run at all. The timing, every minute, also seems to be an issue as for both a repeating job and worker the minimum interval is 15. This one minute doesn’t have to be exact. I imagine instead of having a repeating process loading the data once it might be better to have a long running process sleeping for 1m in between loading the data.

I do not have access to the server the application is connecting to.

What would be the best way to schedule such a background process?

How can the activity best exchange information with that process?

I’m open for all suggestions,
thank you for your time.

Source: Android Questions

LEAVE A COMMENT