0

I have shared preferences in my app

I want to clear it by tapping a button

How I can do this?

I using Xamarin(c#) for making Android app

SharedPreferences code

On first activity:

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
            ISharedPreferencesEditor editor = prefs.Edit ();

And on Second:

    ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
        string product = prefs.GetString ("title","");
        string _weight = prefs.GetString ("weight","");
        string _price = prefs.GetString ("price","");
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Nope. This is Java, I need c# @matthewrdev –  Nov 30 '15 at 23:46
  • A quick port: `prefs.Edit().Clear().Commit();` – matthewrdev Nov 30 '15 at 23:57
  • Error CS0029: Cannot implicitly convert type 'bool' to 'Android.Content.ISharedPreferencesEditor' (CS0029) Have this Error @matthewrdev –  Dec 01 '15 at 00:04
  • matthewrdev's code looks correct to me, @Eugene. `.Edit()` returns an `ISharedPreferencesEditor`, then `.Clear()` returns the same object, (`ISharedPreferencesEditor`), then `.Commit()` returns a boolean. How are you trying to use it? – Simon MᶜKenzie Dec 01 '15 at 04:41
  • Maybe it doesn't works? @SimonMᶜKenzie –  Dec 01 '15 at 06:40

1 Answers1

0

That's code do this

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            ISharedPreferencesEditor editor = prefs.Edit();
            editor.Clear();
            editor.Commit();