Help with onShow() and onHide() Widget

Former Member
Former Member
Hi,
I have the following issue:
I created a widget based on the WebRequest sample. Receiving data is working fine.

I want to save the state of my widget so it slides in with the latest data.

If I load the app on my device Forerunner 935 scrolling through the watch restarts my widget (Showing the app name and icon) instead of using onShow(), onHide().
Using "Force OnHide and Force onShow is working fine on the simulator.

Gif of the behavior https://media.giphy.com/media/3o6nVbiuHFNcP9FYnm/giphy.gif
  • The way I do this is when I get the data, I save it to the object store (in onReceive or in onBackgroundData) And when the app starts, load it in initialize() and use it if I don't consider the data to be stale (based on a timestamp)
  • Former Member
    Former Member
    Your widget will not stay in memory if you navigate away from it. If you want to save your state to reload it without making a web request, you should store this information using the persistent application storage [AppBase.get/setProperty() or the new 2.4.0 APIs in Application.Storage].

    onHide()/onShow() would occur in situations where you have not closed the widget by navigating away from it, such as a smart notification popping up when you are viewing the widget.
  • Former Member
    Former Member
    Application.Storage is exactly what I was looking for. Thanks