I'm using the shared preferences to store login credentials for my app. Everything works fine except with one user. After a certain amount of time the shared preferences seem to be reset or cleared somehow. I've adjusted my app for this user to never clear his shared preferences anymore. This way I can be sure that it is not my app's fault. But even after this modification his credentials get cleared, so I'm suspecting something else is going on with his device.
Do any of you have suggestions on how to approach this problem? I've been thinking about creating another app which sets a fileobserver to monitor the preference file. This way I hope to see when the file gets cleared/deleted. Maybe there are apps who can do this already? I'm even willing to make the preference file available to other apps for checking. Is there any one way to diagnose this problem? I'm sure it's not my app doing the clearing / resetting...
Thanks for any help you can give.
Several things to consider. First, if you can, simply use a database as they are much more dependable. Second, do not use a SharedPreferences object across processes, which is likely not applicable to this situation. Third, when reading SharedPreferences you have to use the same precautions when writing them. Use a single SharedPreference object, and a single Editor object. Pass the SharedPreferences object around to your methods and class, you don't have to reuse the Editor. In the past I've had a user a day complain about SharedPreferences getting deleted, but once I implemented some of these logical steps my users stopped annoying me. Bare in mind, just like you said, it's rare. 1 in 1500 users is is a negligible percentage, but even a single user can leave a bad comment :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With