chobo2
chobo2

Reputation: 85735

How to Save private preferences with monodroid?

I am trying to save some settings but the tutorial I am following(android tutorial) is not helping as I am stuck on the first line of code since it seems monodroid does it differently?

             select your mode to be either private or public.

int mode= Activity.MODE.PRIVATE;

// get the sharedPreference of your context.

SharedPreference s mySharedPreferences ; mySharedPreferences=getSharedPreferences(“Name_of_your_preference”,mode);

// retrieve an editor to modify the shared preferences

SharedPreferences.Editor editor= mySharedPreferences.edit();

/* now store your primitive type values. In this case it is true, 1f and Hello! World  */

editor.putBolean(“myBoolean”,true);

editor.putFloat(“myFloat”,1f);

editor.putString(“myString”,” Hello! World”);

//save the changes that you made

editor.commit();

I don't see Activity.MODE.PRIVATE; in monodroid.

Upvotes: 1

Views: 2168

Answers (2)

mironych
mironych

Reputation: 2978

Here is my func to do this:

protected void SaveSetting(string name, string value)
    {
        var prefences = GetSharedPreferences(Consts.Application.SETTINGS_FILE, FileCreationMode.Private);
        var editor = prefences.Edit();
        editor.Remove(name);
        editor.PutString(name, value);
        editor.Commit();
    }

Upvotes: 6

jpobst
jpobst

Reputation: 9982

Assuming you mean MODE_PRIVATE, it should be Android.Content.FileCreationMode.Private.

Fortunately you don't really have to know that, as we mapped the int in GetSharedPreferences to take the Android.Content.FileCreationMode enum, so intellisense should help you out.

Upvotes: 3

Related Questions