How to replace osolete CursorLoader in Xamarin?

85 views Asked by At

I'm developing an application in Xamarin for Android which needs to get a list of calendars. I've found an example how to do it but there is used CursorLoader which is mark as deprecated. I wasn't able to find a replacement of the function in Xamarin. Is there an another way how to get list of calendars? Thanks.

AndroidCalendarModels _androidCalendarModel = new AndroidCalendarModels();
            string[] calendarsProjection = {
                CalendarContract.Calendars.InterfaceConsts.Id,
                CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName,
                CalendarContract.Calendars.InterfaceConsts.AccountName 
                };

            var calendarsUri = CalendarContract.Calendars.ContentUri;            
            var loader = new CursorLoader(Android.App.Application.Context, calendarsUri, calendarsProjection, null, null, null);
            var cursor = (ICursor)loader.LoadInBackground();

            while (cursor.MoveToNext())
            {
                int calId = cursor.GetInt(0);
                string calName = cursor.GetString(1);
                string calAccount = cursor.GetString(2);

                _androidCalendarModel.Calendars.Add(new AndroidCalendarModel()
                {
                    Id = calId,
                    AccountName = calAccount,
                    CalendarDisplayName = calName,
                });
            }
0

There are 0 answers