0

in my app I use 3 broadcast receivers for the following broadcasts:

android.net.wifi.STATE_CHANGE
android.intent.action.ACTION_POWER_CONNECTED
android.intent.action.USER_PRESENT

Now, before Android O, everything was working fine. But since new limitations on background work, I'm having trouble with those broadcasts. I constantly need to receive broadcast on events like change in WIFI state, or if the is device still or is in motion, even when the app isn't running.

I tried using JobScheduler to listen to wifi broadcasts, but it seems that the system still kills the service after certain time, moreover it stop working when I swipe the app out from recent-apps.

I was thinking, is using foreground service, to register the broadcast, is a good idea to solve this problem?

What would you suggest to solve this problem?

Keselme
  • 3,779
  • 7
  • 36
  • 68

1 Answers1

0

According to Android documentation usage of Manifest's implicit broadcast receivers is deprecated in Android Oreo and above

https://developer.android.com/about/versions/oreo/android-8.0-migration.html#rbr

mitesh makwana
  • 269
  • 3
  • 11
  • Yes, I know that, what I'm asking is how to overcome this obstacle, so I'll still be able to receive broadcasts constantly. – Keselme Dec 19 '18 at 09:08
  • refere this answer https://stackoverflow.com/questions/47110489/background-service-for-android-oreo – mitesh makwana Dec 19 '18 at 09:13