8

I have a WearableListenerService on a phone app that receives a DataItem from the watch (in onDataChanged). The code is essentially the same you have on the documentation (I can put it here if useful).

When a new DataItem is received, I show a notification to the user on the phone.

It works for Android 5, regardless if the app is running or killed. It also works on Android O API 26 if the app is running/in memory, but it doesn't if I kill the app first (by swiping): the WearableListenerService does not run then.

I'm aware of the background execution limits on Android 8, but I don't how to deal with them in this case since it's Android that should start the service while my app is in background so that I can react to the Data Layer changes.

Is there a way to listen for Data Layer events on Android 8 while the app is in background?

Albert Vila Calvo
  • 15,298
  • 6
  • 62
  • 73
  • "but it doesn't if I kill the app first (by swiping)" -- what device(s) are you testing on? – CommonsWare Sep 23 '19 at 23:04
  • It happened with a **OnePlus 5T**. This device is very aggressive with background limits and doze mode. There is a screen in the Settings -> Battery -> Battery optimization in which you can relax the background "optimizations" for specific apps (you can see this screen [in this blog post](https://www.guidingtech.com/fix-oneplus-battery-optimization-reset-issue/), at the bottom, where it says "3. Disable Deep Optimization"). – Albert Vila Calvo Sep 24 '19 at 17:55
  • I don't have any Wear OS app experience, and I have not used `WearableListenerService` as a result. If you are in position to test on another device, it would be interesting to see if the problem is tied more specifically to devices with aggressive power management. For example, it is possible that "Disable Deep Optimization" does not cover this scenario, due to a bug or an intentional decision by the OnePlus developers. – CommonsWare Sep 24 '19 at 23:09
  • Did u get any solution ? – Akshay Shah Jun 05 '20 at 12:15
  • @AkshayShah no sorry :( Maybe you could try to disable the battery optimization on the phone, but you can only do this on your phone, not for everyone. – Albert Vila Calvo Jun 05 '20 at 13:23
  • Yes I implemented it by asking user not to optimize the app when the app starts. Though a bad solution but had to do it this way. – Akshay Shah Jun 05 '20 at 17:30

0 Answers0