Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 267
Robert M. Avatar asked Mar 13 '23 08:03

Robert M.


1 Answers

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

like image 78
tynn Avatar answered Apr 27 '23 10:04

tynn