How do I allow my Android companion app to receive messages at any time without getting killed by the OS?

I've built an app that records the user's weight. It transmits a message to an Android companion app that records the weight in Google Fit. I don't know when the user is going to enter a weight on the watch, so the companion app needs to be available to receive messages at all times. I've set up an Android Foreground Service to receive the messages, but that gets killed after a few hours. 

Is it true that the only way for the Android companion to receive messages is set up a ConnectIQ.IQApplicationEventListener and wait for onMessageReceived() to be called? That's what I'm doing, but it means I need a way to keep the ConnectIQ instance alive in my Android app. The OS only allows the foreground service to live for a few hours, then it kills my service. 

Android docs recommend using the WorkManager, but if my app needs to be running to receive the message from the watch, I don't see how that would work.

What's the right way to handle this?

Can I send a persistent message from the watch to the app that lives in a mailbox? Then my companion app could pick it up.

Is there an Intent that the Connect IQ app can send to my companion app to wake up or receive the message? That way it wouldn't need to run as a foreground service. 

Top Replies

All Replies