How to use Shared Preferences in Android – Mobile App Development, Android App Development, iphone App Development class="post-template-default single single-post postid-4103 single-format-standard wp-custom-logo"

How to use Shared Preferences in Android

Download APK Download Source Code Contact Us

Create a new project in Android Studio

File – New Android Project

How to use Shared Preferences in Android
How to use Shared Preferences in Android

Shared Preferences

Shared Preferences is allow you to save and retrive data in the form of key, value pair.You can use sharedpreferences to save any primitive data,booleans,floats,ints,longs and string.

Use Shared Preferences

[code lang=”js”]getSharedPreferences()- Return sharedPreferences instance poiting to the file that contains the values of preferences. [/code]

[code lang=”js”]SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); [/code]

You can save something in the sharedpreferences by using SharedPreferences.Editor class. You will call the edit method of SharedPreference instance and will recieve it in an editor object.

[code lang=”js”]
public static final String USER_DETAILS_PREFS = "user_details_prefs";
private static final String NAME = "name";
public static String getName(Context context) {
SharedPreferences sp = context.getSharedPreferences(
USER_DETAILS_PREFS, Activity.MODE_PRIVATE);
return sp.getString(NAME, "");
}
public static void setUserDetail(Context context, String name) {
SharedPreferences sf = context.getSharedPreferences(
USER_DETAILS_PREFS, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sf.edit();
editor.putString(NAME, name);
editor.commit();
}
getPreferences()- Use this from an Activity if you need to use only one shared preference file for the activity.
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);

[/code]

Deleting key value from sharedpreferences

[code lang=”js”]
SharedPreferences sf = context.getSharedPreferences(
My_PREFS, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sf.edit();
editor.remove(“key_name1”);
editor.remove(“key_name2”);
editor.commit();
[/code]

Clear all data from sharedPreferences

[code lang=”js”]
editor.clear();
editor.commit();
[/code]

How to use Shared Preferences in Android
How to use Shared Preferences in Android
How to use Shared Preferences in Android

Download APK Download Source Code Contact Us


Warning: _() expects exactly 1 parameter, 2 given in /home2/mobilemeri7/public_html/wp-content/themes/mobilemerit/comments.php on line 28

Write a Reply or Comment

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Cracked Accounts Free Netflix Accounts VPN Proxy Shares Hack Programları Hack dökümanları Hack methodsları Wordlist Combolist Warez Scriptler Download Warez Files WhatsApp Numara çekme +90 Abazalardan Para kazanma Telegram Mavi tik alma 2022 Numara sorgulama Azuere Aws Sanal Kart Method WhatsApp vurma Güncel Method 2022 Bedava .Com .Org .Net VDS Premium Host YouTube Sahte Telif Methodu Tıklama hilesi ile para kazanmak Azure Hack method Pubg Mobile Uc Almak Hedef Kişinin herşeyini öğrenmek instagram Telif taslağı 2022 Ölüm Belgesi ile instagram hesap kaptma instagram form ile ebedi hesap kapatma instagram taklitsiz hesap kapatma instagram Çift faktör geçme instagram tiktok hesap çalma method instagram 2 Faktörlü doğrulama geçme instagram hesap kapatma 2022 instagram rever kırmak instagram Revert Kırma Abaza Dayı Methodu Aylık Dolar kazamak 1500 dolar instagram Çalmak istiyorum instagram düşmeyen takipçi instagram hackleme sitesi Whatsapp Kapatma %100 Abaza tokatlayarak para kazanmak Spotify ile para kazanma Günde 100 tl kazanma sınırsız kazanç Yatakta yatarak para kazanma YouTube izlenme arttırme yöntemi Oturduğun yerde para kazanma yöntemi Discord Hack tool Discord hack programları Cerebrus Rat v2 kodları PP Takipçi Çeken Telif Scripti Facebook profil kapatma methodu 2022 instagram yapay ile banned methodu instagram hesap satşı Sosyal medya hesap satışı Sosyal medya hack Leak Forum Crack Forum Cracking Forum Warez Forum Hack Forum illegal Forum Hacking Forum instagram Forum instagram Forumu Hacklink Hack forum php Shell indir Hack haber
https://www.ankihlasnakliyat.com/jigolosahibinden.comankara nakliyatankara nakliyatistanbul nakliyatankara nakliyatJigolodiyarijigolo sitesigerçek jigolo sitesijigolo sitelerimjigolo şirketlerijigolo sitelerijigolo başvurujigolo arayan kadınlara ulaşKocuceKo cuce