0

I have an application running on an industrial Android handheld, on client premises, wifi, no internet. The app communicates with a REST API with our in-premises server.

I'd like to add a notification system to this app, even simply a polling of the server every 5 minutes. I understand this must be done with a service, and I've tried many implementations of backgrounding with Xamarin, that work as long as the App is running (foreground or background), but the service stops when the App gets closed.

So my problem is: can I create an (almost) unstoppable service? is yes, is it possible with Xamarin?

I don't know if it is pertinent, but apps like TripAdvisor have a permanent service running in the background, that if I kill it gets reloaded. And I guess this service collects your position, sends it to their server, and if I'm in a certain place opens a notification and asks me to vote for it. Does it works this way?

Mattia Durli
  • 757
  • 7
  • 19
  • What API level are those devices? – SushiHangover May 15 '18 at 12:56
  • Yes, but it would need to be a foreground service, which means that you would have to have a notification showing this. – Cheesebaron May 15 '18 at 12:56
  • I would recommend using JobScheduler and make the necessary API Calls in the service and send local notification. If it works. Not sure how to use it in Xamarin. – dhiku May 15 '18 at 13:04
  • JobScheduler wouldn't guarantee the same latency a persistent service would – Cheesebaron May 15 '18 at 13:41
  • @Cheesebaron Actually the min. PeriodicWorkRequest for WorkManager is 5mins and WorkManager abstracts how it runs on the different APIs. Xamarin does not have binding for `androidx`, but I been using it on Android One-based API O (production) & P (prototypes) and highly recommend it (made our own binding for it). It is the way of the future for getting work started on Android (including spinning of a Service on a repeated basis) as with API P, the time of endless services, even foregrounded, is coming to an end. Oreo started it as it can background/suspend your foregrounded service at will. – SushiHangover May 15 '18 at 14:07
  • API level is 25. I'll check JobScheduler, but seems to me that it will close, when app closes, am I wrong? Foreground service seems a good solution (notification is not an issue), and my target is Android 7.1 (but you say that from 8.0 on it wouldn't be reliable anymore?) I found WorkManger doc, but there's no Xamarin binding. So you suggest to use WorkManager to spin up a service periodically if it gets shut down? – Mattia Durli May 15 '18 at 21:49
  • Consider Pushy (https://pushy.me/), a paid push notification gateway that can be self-hosted on-premises and supports Xamarin. Full disclosure - I founded Pushy. – Elad Nava Aug 25 '18 at 10:02

0 Answers0