0

I am wildly confused with the current Android background service possibilities and need some help from an expert :)

The "xDrip" application is broadcasting its information via an (I guess implicit) intent with the action name "com.eveningoutpost.dexdrip.BgEstimate". I want to receive these intents. As it is not allowed to put them into the manifest I registered them dynamically in the onCreate() method of my application class. This is working great as long as the app is running (even when the app is not open on screen). But if I swipe it away in the app overview, it does not receive the intents any more even though I do not unregister the intent.

My question is now: What would be the most suitable way to receive this (implicit) intent reliably all the time? So also when the user swipes the app away in the app overview screen?

Cheers!

JUehV
  • 53
  • 7
  • 1
    Run a foreground service to keep your app alive, there isn't really much to work around with. – Pawel Feb 09 '20 at 21:01

1 Answers1

3

This is working great as long as the app is running (even when the app is not open on screen).

More precisely, this is working great so long as your process is running.

But if I swipe it away in the app overview, it does not receive the intents any more even though I do not unregister the intent.

More precisely, you stop receiving the broadcasts once your process stops running. Note that this will happen naturally while you are in the background, even without a manual swipe of your app off of the overview screen.

What would be the most suitable way to receive this (implicit) intent reliably all the time?

Technically, it's impossible.

You will get close if you use a foreground service, to keep your process around longer. However:

  • The user can still swipe the app off the overview screen, and this might still stop your service and terminate your process

  • Even a process with a foreground service might be terminated by Android automatically after a substantial period of time

  • Your app will be consuming system RAM the entire time, which users may or may not appreciate

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for your detailed information! I have some followup questions: I use a medical app for receiving glucose values via bluetooth on my Android phone. This app has a constant low prio notification. (I guess this is a result of the forecround service?!) I tested to stop the process via swiping the app off and it continues running. How does this work? Or is there way to restart the app automatically after a process kill? – JUehV Feb 10 '20 at 12:51
  • @JUehV: "How does this work?" -- they might have the service in a separate process from the UI (via an `android:process` attribute on `` in the manifest). However, do not assume that this will resolve this problem on all devices, as device manufacturers sometimes modify this "swiping the app off" behavior and might take steps to ensure that even separate processes get terminated. – CommonsWare Feb 10 '20 at 12:56
  • @JUehV: "Or is there way to restart the app automatically after a process kill? " -- not really, because too many developers abused this sort of thing. – CommonsWare Feb 10 '20 at 12:57
  • Ok foreground service seems to be good enough :) Thank you very much! – JUehV Feb 11 '20 at 15:56