I’ve just discovered a long-standing mistake in my code going back to 2013. Yikes!
Make sure to use system.ApplicationSupportDirectory and not system.CachesDirectory if you want state to persist between app launches.
From the docs on system.CachesDirectory:
Used with system.pathForFile() to create a path for storing and retrieving files that are available across application launches. This is ideal for saving state information.
I question that information in the docs.
I was using system.CachesDirectory and recently discovered that the contents of the directory are purged. In-app purchases, progress and other app state data can be lost if you use system.CachesDirectory to save state. I have now switched to system.ApplicationSupportDirectory
I hope you don’t make the same mistake as I did! More here:
Are you using system.ApplicationSupportDirectory to save state (e.g. progress and in-app purchases) in your app? I’d be interested to know your thoughts.