Delete SharedPreferences created dynamically

1

In order not to have to redo requests that have already been brought from the server, I persist them using SharedPreferences ... Only they are created dynamically in my app. example:

// essa key é unica para cada post
// ex: MINHA_KEI_1, depois MINHA_KEI_2, e assim por diante...

SharedPreferences  save = contexto.getSharedPreferences(key, Context.MODE_PRIVATE);
SharedPreferences.Editor saveEdit = save.edit();
Gson gson = new Gson();

String jsonPost = gson.toJson(posts);
saveEdit.putString("POST", jsonPost);

saveEdit.commit();

Except after a while, I want to delete all of them for the hand app to get very large.

How do I delete all of them at once, even without knowing the KEY?

I thought of creating a sharedPreferences with the generated keys, and then go through each one and delete ... I do not know if there is any other way.

    
asked by anonymous 05.11.2016 / 18:26

2 answers

3

Hello, to delete shared preferences, just use the following code snippet:

SharedPreferences save = contexto.getSharedPreferences(key, Context.MODE_PRIVATE);
SharedPreferences.Editor saveEdit = save.edit();
saveEdit.clear(); 
saveEdit.commit();
    
07.11.2016 / 00:33
-1

Hello, the method's official documentation does not cite any method to remove all sharedPrefferences from your app via code without mentioning the shared key.

The only time it clears completely (and without the need for the key) is when the app is removed - but programmatically, I do not believe there is a way to clean up as it is done when uninstalling the app.

    
07.11.2016 / 10:21