Tutorial: Define Application Properties 2

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. .

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!

2 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.

Leave a Reply