Search code examples
androidsqlitesharedpreferencesandroid-memoryandroid-database

In which case user can clear shared preferences but not DB


As I know, when a user does "clear data" or "disable" any application, it's shared preferences are cleared and database is also cleared.

So my question is,

Is there any case, that user can perform, in which shared preferences gets cleared but database remains intact ?


Solution

  • Clear Data will clear everything, Shared Preference, Cache, DB.

    If you really want to clear only shared preference (some/all) you can do it programmatically by iterating over Shared Preferences like this:

    Map<String, ?> allEntries = prefA.getAll();
    for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
        Log.i("debug", entry.getKey() + ": " +  entry.getValue().toString());
        //put delete/edit logic here for some shared preference
    } 
    

    This logic can be placed based on your app version, or some other logic like when user logs out, but this action would be performed in your app only.

    I dont think Android Applications settings allows any option where you can clear only shared preferences and not local db.