Robert McLendon Robert McLendon - 1 year ago 138
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 Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download