Keep List of contacts in storage

rozek1szymonrozek1szymon Member ✭✭
edited February 17 in Xamarin.Forms

Hi, I have encountered some problem, I have 600 contacts in my application.
I fetch them with CrossContactService : var contacts = await CrossContactService.Current.GetContactListAsync(); But when after that I call an API to check which numbers are in database, it takes about 5 sec when I have that amout of contacts. My question is that, I dont want to call api every time to get informations about which contact is in database, so I want to keep this information in App, to get the information (List of this numbers) faster. My one contact info is a class

public class ContactsListModel
    public string Number { get; set; }
    public string Name { get; set; }
    public bool App { get; set; }

Tell me the best way to keep list of this object somewhere, or other idea which doesnt contains callin api every time I want to use this contacts. I know that something like current prop or crossSettings exist in xamarin, but is it a good solution to keep list of e.g 300 contacts. I am new in xamarin field so thanks for your help



  • ColeXColeX Member, Xamarin Team Xamurai

    Check the following options for persistence


             List<Model> list = new List<Model>();
            list.Add(new Model() { name = "1" });
            list.Add(new Model() { name = "2" });
            var listString = JsonConvert.SerializeObject(list);
            Preferences.Set("my_key", listString);


            var myValue = Preferences.Get("my_key", "default_value");
            List<Model> list = JsonConvert.DeserializeObject<List<Model>>(myValue);

    PS : You need to install Newtonsoft.Json first.

Sign In or Register to comment.