Search code examples
androidpropertiesassets

Write properties file on Android


Following this android's Guide I created method to write data on a properties file .

My properties file is inside asset folder, with 2 other properties files:

enter image description here

This is settings.properties file:

#DEBUG
debugMode = false

#WIZARD
showWizard = true

This is my method (inside an AppCompatActivity):

  SharedPreferences settings = getSharedPreferences("settings", 0);
  SharedPreferences.Editor editor = settings.edit();
  editor.putBoolean("showWizard", false);
  editor.commit();

The problem is that when I try to read the field "showWizard" I always get true, but when I edit the field "showWizard" with the method above, I don't get any error and it seems that the field was correctly turned from "true" to "false". But it isn't!

Does anybody understand where is my error?

Thank you


Solution

  • Following this android's Guide I created method to write data on a properties file .

    The word "properties" does not appear on that page.

    Does anybody understand where is my error?

    Those properties files that you have in assets/ have absolutely nothing to do with SharedPreferences. If you want to read an asset, use AssetManager and its open() method. That will give you an InputStream that you can pass to load() on a Properties object.