Tutorial: Define Application Properties 4

In the previous tutorials we learned how to do unit testing. We’re going to use that project as a starting base to add application properties on top, so you can use your project you made so far or download my project from github as a starting version. .ads in wordpress

Application properties: Why?

Application properties allow you to make your project configurable by the user. The user enters the values for the parameters you have defined and in our connect iq program we work with what the user has provided us.

Defining the properties

The properties are defined within the resources folder, you can give it any name and store it anywhere in the resources folder structure, but I like to call that file properties.xml and store it in a folder called settings for clarity. We also have to define a new set of string resources for the titles, you can store this within the properties.xml or within the strings.xml file you already have. In this case I’ve added it to the strings.xml file (mainly because I added multiple language support to this project)
This is what it looks like:

Get the settings

Retrieving the settings is pretty straightforward via Application.getApp().getProperty(…). This will retrieve the application properties at initialization time. When you wish to let the user change the settings while the application is running then you also need to implement the onSettingsChanged() function.
All we have to do now is do something with the settings that we read and use them in the compute function.
You can download the full source code from github

That’s all…

… or is it?

Well if we run the unit tests we get an error….

That’s not good! We’ll see in the next tutorial how to fix this!


Did you like this article?Questions?
  • Post in the comments section below!

4 thoughts on “Tutorial: Define Application Properties

  1. Reply MazeFest Apr 19,2019 19:09

    How do you get the properties to save to the resource file? I’m able to set the property and use it. but once I restart the app, it isn’t saved. Also the XML file never changes Value?


    • Reply Peter Apr 22,2019 07:42

      the application properties are not saved in the xml file, they are saved in a seperate (and encrypted) file. The settings are stored in a .set file.

  2. Reply Jaap Feb 24,2020 10:57

    Normally I can change the settings of a watch app in ConnectIQ, but when I copy an app to GARMIN/APPS of my watch myself, I can use it and the app is shown in ConnectIQ, but I can’t change the settings. I tried the apps in connectiq-sdk and Kudo and StepsCarousel.

    GARMIN/APPS/SETTINGS/KUDOS.SET is created, but no settings option is shown in ConnectIQ or Connect.

    • Reply Peter Feb 24,2020 11:11

      You can’t do that for sideloaded apps indeed. The easiest is to upload your app as a beta app then you can use the mobile app to change settings. An alternative way is to do a send settings from within the simulator and copy the .SET file from within the %TEMP%\Garmin folder. (but I’d recommend going for the beta app way)

Leave a Reply