Best practises

Hi there!

i just developed my first own watch face. But now, i got some question regarding best practises and battery lifetime.
So here are my questions:
  • I display the heart rate. Currently i draw a heart and the number in the onUpdate method. Since only the displyed heartrate and not the drawn heart will change, is it sensible to put all drawings in the initialize method? (i draw more than just a heart). Where's the best place to put the code for drawing images that actually never change(only the values)?
  • In another thread somebody told me about object store. I'm developing fore the FR 235 which supports SDK 1.4. The documentation tells me, that i need SDK 2.4 for using object store, correct? So i can't use the object store within my watch face for the FR 235?
  • Since i want to store e.g. the last known GPS position and object store is propably not available for me (see #2), what's the best way to store the last known GPS position? A class variable where i just it? Or any better options?
  • My idea is also to use a user-defined location if no GPS and no historical GPS location is available. Also like mentioned in #2 the properties were introduced in 2.4 and i can't use it in SDK 1.4, correct?
  • While testing the watch face on my FR 235, i noticed that switching between the watch face and other app like showing HR is quite laggy. If i press the down button, the new app occurs quite quickly and without any lags but switching back results in my watch face showing with some lags. Any Ideas why and how i can create asmooth transition? (the sim tells my i'm using 17/64 kB memory, so this shouldn't be an issue, right?)
TIA :-)
  • Former Member
    Former Member over 7 years ago
    I display the heart rate. Currently i draw a heart and the number in the onUpdate method. Since only the displyed heartrate and not the drawn heart will change, is it sensible to put all drawings in the initialize method? (i draw more than just a heart). Where's the best place to put the code for drawing images that actually never change(only the values)?

    The initialize() method should be for setting up the class before any drawing has occurred. onLayout would be the first place where you can draw to the screen, and if you are confident that nothing will creep into those unchanging regions then it should be fine to draw the heart there. Make sure that a minute hand isn't going to come sweep that area out though.

    In another thread somebody told me about object store. I'm developing fore the FR 235 which supports SDK 1.4. The documentation tells me, that i need SDK 2.4 for using object store, correct? So i can't use the object store within my watch face for the FR 235?

    The object store has been in since 1.0.0, and it should work fine on the fr235. I believe it is the newer Application.Storage module that requires 2.4.0. The Application.Storage module won't replace the object store for a long time, so you should have no trouble using the object store across devices.
    See here for versioning: https://developer.garmin.com/downloa...nstance_method

    Since i want to store e.g. the last known GPS position and object store is propably not available for me (see #2), what's the best way to store the last known GPS position? A class variable where i just it? Or any better options?

    Since the object store is available to you, then go ahead and make use of it. Depending on watches though, the last known GPS position might not be accessible through the usual means. I believe this is the case on the 5X, but feel free to correct me. - Jim knowns best, see below.

    My idea is also to use a user-defined location if no GPS and no historical GPS location is available. Also like mentioned in #2 the properties were introduced in 2.4 and i can't use it in SDK 1.4, correct?

    In such cases, you could use application settings, where the user would go into Garmin Connect Mobile and set a default location for this app. That would probably be the easiest way to set it in a watch face. On 2.x devices where it is supported, you could make use of a web request to grab their location in the background.

    While testing the watch face on my FR 235, i noticed that switching between the watch face and other app like showing HR is quite laggy. If i press the down button, the new app occurs quite quickly and without any lags but switching back results in my watch face showing with some lags. Any Ideas why and how i can create asmooth transition? (the sim tells my i'm using 17/64 kB memory, so this shouldn't be an issue, right?)

    The latency would come less from total memory used, and more from total time spent in watch face setup. If you have a bunch of beefy computations going on in the initialization or long draw calls in the first layout and update, then you can expect it to be a slower transition.
  • The lat/lon by way of Activity.Info (the currentLocation) works fine of the f5x. In the early days, you could only get it when the watchface was in preview mode

    Doing the drawing in onLayout may be an issue when the top part of the screen is covered with a notification, etc.

    The safest is to redo the whole screen in onUpdate().

    update:

    There is one thing that differs on a f5x here.... Activity.Info.currentHeartRate will always be null This comes into play if you want to update the HR using 1hz/onPartialUpdate(). The HR only will change when the history from getCurrentHeartRate changes, and not when Activity.Info.currectHeartRate changes.
  • Hi,

    thanks for all the responses.
    One more question: When is the object store whiped? I need to know that because i tested the object store and stored datat there.
    Now my code runs not the execution because the parameter is set.

    Or should i call clearValues on initialize to reset my object store? When/How often is initialize called?
  • The object store is in \garmin\apps\data on the watch. The Pre "Application.Storage" ones are named .str.

    (BTW, the settings file is in \garmin\apps\settings and end in .set)
  • Former Member
    Former Member over 7 years ago
    One more question: When is the object store wiped? I need to know that because i tested the object store and stored datat there.


    The object store is cleared when the app is uninstalled. You could manually go in and clear it, but unless either GCM, express, or a user uninstalls the app then the store should not get cleared.

    When/How often is initialize called?


    initialize() is called at class instantiation, so in the case of the view class of a watchface, which extends WatchUi.WatchFace, initialize() would get called whenever that view is created. Depending on how you set it up, this might be during getInitialView() in the base app class. In that case, it is called after onStart() when in app is starting up. See here for more info: https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Application/AppBase.html