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.

Crack Accounts admin panel bypass Tiktok hackleme sitesi Nulled Scripts Nulled Script ioncube decoder iphone sızma valorant hackleme Crack script Brute force programı Brute force yapma internetten para kazanma Evde para kazanmanın yolları Öğrenciler için internetten para kazanma yolları valorant combo Brute force programı Açıklı siteler SQL Açıklı siteler CMS Brute Force https://www.ankihlasnakliyat.com/su kaçağı bulmasu tesisatçısıjigolo siteleri arkadaş bulankara nakliyatankara nakliyatistanbul nakliyatgay sohbetbatak oynatavla oynagabile sohbetokey oynaoyunlar oyna #yaslikurt# sex geschichten sex geschichten brazzers rot media instagram banned service Hack haber Hacklink satışı Hacklink Çift faktör kıran telif scripti instagram hackleme sitesi instagram hackleme sitesi Bahis scripti Hack sitesi Crack forum Crack forum Crack Crack Forum instagram hackleme sitesi instagram hesap kapatma instagram hesap kapatma formları instagram hesap kapatma method instagram faktör geçme instagram faktör kırma instagram telif scripti Instagram Telif Scripti 2022 instagram hackleme sitesi apili telif scripti Facebook Temalı Telif Scripti