androidiosxamarinbackground-processmaui

.NET MAUI Recurrent Background Job that runs few times a day


I would like to have a background job to run like 2-3 times a day, but even less it's ok. It's just a quick api call to my server, it doesn't need to update the UI, infact I prefer that it runs when the app is not in the foreground, but that's another topic.

I've read that latests versions of Android and iOS or even manifacturers restrict the app but I don't need these task to be at certain time precisely. I'm not sure if I should use the JobScheduler or WorkManager for Android and the BackgroundFetch or BackgroundTask for iOS.

Let's say the task should run 3 times a day so every 8 hours roughly. The thing is that a user might not open the app again so the task should be scheduled to be recurrent, maybe every time it runs it could schedule another one, but if one fails that line could never be reached.

I don't need to support old operating system version, only iOS 15+ and Android api 30+.

Thank you for the help!


Solution

  • Apple is strict about hardware resources occupied by App, not to mention App in the background state. When App enter the background state, it will soon be suspended by the OS, unless you apply for permission from OS. Only several modes could be allowed to run in the background, see the following picture

    enter image description here

    You want a background cron job which is not allowed in iOS.

    For Andriod, you know we could use WorkManager or JobSchedule. Here are some documents that you could refer to:

    Getting Started With WorkManager

    Android Job Scheduler

    Hope it works for you.