In this tutorial, we will see how to use the local storage preferences in the
.Net MAUI application. Preferences is stores data in key-value pairs and can
be easily managed via the Preferences class from Microsoft.Maui.Storage
namespace.
Note:If we uninstall the app, will remove all local preferences.
Platform differences
Preferences are stored natively, which allows you to integrate your settings
into the native system settings.
- Android:All data is stored into Shared Preferences. If no sharedName is specified, the default Shared Preferences are used. Otherwise, the name is used to get a private Shared Preferences with the specified name.
- iOS/macOS:NSUserDefaults is used to store values on iOS devices. If no sharedName is specified, the StandardUserDefaults are used. Otherwise, the name is used to create a new NSUserDefaults with the specified name used for the NSUserDefaultsType.SuiteName.
- Windows:ApplicationDataContainer is used to store the values on the device. If no sharedName is specified, the LocalSettings are used. Otherwise the name is used to create a new container inside of LocalSettings. LocalSettings restricts the preference key names to 255 characters or less. Each preference value can be up to 8K bytes in size, and each composite setting can be up to 64 K bytes in size.
Quick Links:
Project Setup:
- Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
- In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
- In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
- In the Additional information window, click the Create button:
- Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app
Implementation:
-
Save/Set Preference will store simple value, preference having different key
and value, preference key always string type, the value of preference must be
one of the following types.
- Boolean
- Double
- Int32
- Int64
- Single
- String
- DateTime
- In Solution Explorer, click MainPage.xaml and replace the page content with what is shown below:
- Open the MainPage.xaml.cs file and the page content as shown below:
In the below statement, will the get the value from existing preference or if preference value is not there automatic or return the default value.
For dropping preference key and value, clear and remove are used. For example, if you are switching to a different user or logging out, this will assist in clearing all preference key and value. We can use remove preference to get rid of a specific key preference in a mobile device.
Kayseri
ReplyDeleteAnkara
Kilis
Sakarya
Bursa
7BPYİP
Muğla
ReplyDeleteSamsun
Eskişehir
Sakarya
Kars
M6XM
aydın evden eve nakliyat
ReplyDeleteyozgat evden eve nakliyat
kırklareli evden eve nakliyat
antep evden eve nakliyat
konya evden eve nakliyat
L0BD
9AA5E
ReplyDeleteBitlis Şehirler Arası Nakliyat
Muğla Şehirler Arası Nakliyat
Karapürçek Fayans Ustası
Urfa Şehirler Arası Nakliyat
Tokat Lojistik
Antep Evden Eve Nakliyat
Çerkezköy Halı Yıkama
Ünye Televizyon Tamircisi
Kırıkkale Şehir İçi Nakliyat
ED765
ReplyDeleteSivas Şehir İçi Nakliyat
Antep Lojistik
Ünye Mutfak Dolabı
Siirt Şehirler Arası Nakliyat
Edirne Şehir İçi Nakliyat
Bartın Parça Eşya Taşıma
Cate Coin Hangi Borsada
Rize Şehirler Arası Nakliyat
Urfa Lojistik
E05E7
ReplyDeleteRaca Coin Hangi Borsada
Bitcoin Nasıl Alınır
Bitcoin Madenciliği Nasıl Yapılır
Kwai Takipçi Satın Al
Görüntülü Sohbet Parasız
Kripto Para Nasıl Oynanır
Binance Komisyon Ne Kadar
Twitter Beğeni Hilesi
Vector Coin Hangi Borsada
106D1
ReplyDeletekraken
kripto ne demek
paribu
canlı sohbet uygulamaları
filtre kağıdı
bitcoin haram mı
bibox
bitget
huobi
E47A6
ReplyDeleteskype whatsapp görüntülü show
58F7A
ReplyDeletecanlı şov siteleri
D6CD0
ReplyDeletewhatsapp görüntülü show