Sterling
Sterling

Reputation: 6635

Sony SmartWatch 2: need to change supportsLowPowerMode() at runtime

I have an app for the SW2 that has a user option for whether the app should use low-power mode (LPM). Which works fine. The problem is that the SW API only calls my app's supportsLowPowerMode() registration method once, when it first starts up. Meaning that if the user later changes the setting in my app, it won't take effect until the whole shebang restarts.

I've tried a few tricks (like killing my app's process) to force a reload, but nothing's worked so far. My last resort is telling the user that s/he needs to reboot the phone before this takes effect, but that's pretty hokey. Is there a better way?

Upvotes: 4

Views: 245

Answers (2)

mldeveloper
mldeveloper

Reputation: 2238

As far as I know there is no way to change this at runtime. Let me double check with my team though just in case there is a way I don't know about.

Upvotes: 1

Sterling
Sterling

Reputation: 6635

The solution is not to try to change your response to supportsLowPowerMode() at runtime, but to start and stop your extension instead.

Basically, if your extension can ever support LPM, then it should be returning a value of true in supportsLowPowerMode(). If the extension's LPM usage can change, you handle that by simply doing different things in the onActiveLowPowerModeChange() handler. Specifically, if the user has chosen NOT to use LPM, you want a handler that looks like this:

@Override
public void onActiveLowPowerModeChange(boolean lowPowerModeOn) {
    super.onActiveLowPowerModeChange(lowPowerModeOn);

    if (lowPowerModeOn) {
        // User doesn't want to use LPM, so stop the app on the SW
        stopRequest();
    }
}

This has the effect of shutting down your extension when the device's backlight turns off, and it'll drop back to its default LPM watchface.

EDIT: I'm reopening this as I've found an unacceptable side effect to the above technique. If your app returns false to supportsLowPowerMode(), the SW2 will keep it running (but paused) in the background when the watch goes to sleep. This means that, when the user "wakes up" the SW2, your app will immediately reappear on screen. Calling stopRequest() (as in my code sample above) disrupts this behavior, requiring the user to reopen your app after awakening the SW2. I've not found any way around this; what's needed is a pauseRequest() instead, but the API doesn't have one.

Upvotes: 1

Related Questions