Storing and retrieving data in Processing for Android

Hi, my name is Alex.

I came in contact with Processing through Arduino a few years ago Since then I have been using processing for personal projects and a as a programming learning tool. A great experience.

Now I decided to take it to Android (not using APDE, still using the desktop processing IDE) and I’m having an issue with storing data in the device.

I know in java mode, the default directory for reading is the data folder, but when you save files the default directory is the sketch folder. When you need to modify a let’s say a setting files, all you have to do is include the path. Not a big deal.

My problem is that my app reads the settings files ok every time, but it does not overwrite it with the new settings. So every time I open the app it loads the same settings, not the user’s preferences. When I try to add the path to the file name, like I would do in Java mode, I get an Android error (File name contains separators error). I am not using external storage btw…

I’m just using loadStrings() and saveStrings().

Any idea? Thank you in advance. =)

I removed the config file (“config.txt”) that I had for my original settings from the data folder.
Apparently, when the app starts it replaces whatever file I modified and stored with that same name, with the original config.txt file that I had in the data folder when the app was exported.

Now when the app is installed and executed for first time it can’t find the file, but catching the exception allows me to write original settings from my code, and save the file. For the next executions of the app it just opens the last saved config.txt like it is supposed.

It is a learning curve, for sure!! =)

Yeah when developing games for android I found that the best way (for me) to save data is by saving it to a csv file. You can store your data in the Table class (look it up in processing’s reference) and then use saveTable() or loadTable() to save/load data.

1 Like