Search code examples
wear-os

keep service active after activity stopped


I am writing an app for Android wear, which vibrates the watch. The problem is that the vibration stopes when the screen goes off.

I tried creating a bound service, but this gets killed as soon as I disconnect from it.

I tried making it sticky, but this does not work as well (see code bellow):

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d("BPM", "Service command start = sticky");
    return START_STICKY;
}

How can I convince wearos to keep the service alive?


Solution

  • Eventually - I ended keeping the screen on for my activity.

    Trick was using:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    Which also work as expected on WearOS. Not strictly answering the question - but solved the original problem. Giving myself the green marker.