开发者

How to Save private preferences with monodroid?

开发者 https://www.devze.com 2023-03-26 10:31 出处:网络
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?

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”,” H开发者_运维百科ello! World”);

//save the changes that you made

editor.commit();

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


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();
    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消