onStorageChanged

https://developer.garmin.com/connect-iq/api-docs/Toybox/Background.html#requestApplicationWake-instance_function

says:

Called when Application storage is changed by the other running instance app

I understand situation that background process change storage app but  what can else change it? is it possible to run 2 instances of the same app?

  • The full description may make things more clear:

    "Called when Application storage is changed by the other running instance, of the app i.e Background Process while the CIQ app is running or vice-versa. Override this function to receive a callback when the storage is updated. Use this function to reload storage data from the application storage."

    It means that the background process is notified when the associated foreground process changes storage, and the foreground process is notified when the associated background process changes storage.

    It isn't possible to run 2 instances of the same app at the same time.

  • 1. so colon after instance is  unnecessary Slight smile

    2. so haw the background process is informed, there is no onStorageChanged in Class: Toybox.System.ServiceDelegate so what does men vice-versa?

  • onStorageChanged() is in AppBase, and both the background and foreground processes are based on the AppBase class. (All apps inherit from AppBase).

    The core topics CIQ page seems to make it pretty clear how onStorageChanged() should work:

    https://developer.garmin.com/connect-iq/core-topics/persisting-data/

    Connect IQ 3.2 introduces the ability to access the Application.Storage module from background processes. The background process can modify storage using Application.Storage.setValue(), Application.Storage.deleteValue() and Application.Storage.clearValues(). When the storage is written from the background process, Application.onStorageChanged() callback will be invoked for the foreground process if the background and foreground process are active at the same time and vice-versa. The application would then have to reload data from storage to reflect updated information.

  • I asked: how background process is informed when storage is changed?

    For vice-versa means: when app change storage background is informed too? I think it doesn't inform (there is no onStorageChanged in serviceDelegate), it has simple to use getValue in onTemporalEvent.

    Simple, both background and app has access to the "same" storage but app is additionally inform about changes on onStorageChanged.

    no information that background inherits from appbase

  • I asked: how background process is informed when storage is changed?

    AppBase is used by both the main process as well as the background service so that function is there for both the main app and the background

  • so in

    Class: Toybox.System.ServiceDelegate

    description should be onStorageChanged ?

  • I don't think you're getting how the different app types (including background processes) work.

    They all inherit from AppBase, it's just that the different app types use different kinds of delegates.

    Like everything except background processes uses getInitialView(). Background processes use getServiceDelegate(). That doesn't mean that the service delegate is all there is to a background process. It also doesn't mean that getInitialView() is all there is to foreground processes. For example, AppBase.onStart() will also run in both background and foreground processes.

    onStorageChanged() is in AppBase, and it will be available to both the foreground and background process as per the docs.

  • You are looking in the wrong place.  It's not in background.  It's in Application.AppBase

  • no information that background inherits from appbase

    I think you have to distinguish between background *events* and the background *process*. The background process inherits from AppBase, and the service delegate handles background *events*.

  • Same as some foreground processes / apps have an InputDelegate that handles input -- it doesn't mean that the InputDelegate is the whole app.