Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete shared preferences data from App in Android

How do I delete SharedPreferences data for my application?

I'm creating an application that uses a lot of web services to sync data. For testing purposes, I need to wipe out some SharedPreferences values when I restart the app.

like image 723
Andrew Avatar asked Sep 10 '10 18:09

Andrew


People also ask

How can I delete shared preferences data?

You use remove() to remove specific preferences, you use clear() to remove them all.

Where is shared preference file stored android?

Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .

How can I see shared preferences in Android?

Open the device monitor by clicking it. Then you need to select the File Explorer tab in the device monitor. Find the data folder and find another data folder inside it. It will contain a folder having the name of your application package and there will be the desired SharedPreferences.

What are shared preferences in Android used for?

A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. Each SharedPreferences file is managed by the framework and can be private or shared. This page shows you how to use the SharedPreferences APIs to store and retrieve simple values.


2 Answers

To remove specific values: SharedPreferences.Editor.remove() followed by a commit()

To remove them all SharedPreferences.Editor.clear() followed by a commit()

If you don't care about the return value and you're using this from your application's main thread, consider using apply() instead.

like image 51
Mark B Avatar answered Nov 29 '22 11:11

Mark B


My solution:

SharedPreferences preferences = getSharedPreferences("Mypref", 0); preferences.edit().remove("text").commit(); 
like image 20
vaibhav vijay Avatar answered Nov 29 '22 10:11

vaibhav vijay