Robert McLendon Robert McLendon - 5 months ago 14
Android Question

Why is SharedPreferences persisting after reinstall in Android Studio using emulator?

In my understanding, SharedPreferences data is not supposed to persist after a reinstall. I have coded the logic of my app accordingly.

However, using testing on an emulator in Android Studio, I'm seeing the SharedPreferences persist even after I rebuild and reinstall the app. This occurs even if I close and restart the emulator.

Can anyone explain this (seemingly) odd behavior?

Answer

SharedPreferences are stored in your internal data directory in XML files. As long as you don't delete your application, these files persist.

From the documentation:

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

Comments