{"id":3749,"date":"2013-05-19T15:46:52","date_gmt":"2013-05-19T12:46:52","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=3749"},"modified":"2013-05-19T15:46:52","modified_gmt":"2013-05-19T12:46:52","slug":"android-sharedpreferences-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/","title":{"rendered":"Android SharedPreferences Example"},"content":{"rendered":"<p>In this example we are going to see how to use Android\u00a0<a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a>. You can permanently\u00a0store preferences using\u00a0<a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a>\u00a0with the form of a pair : key and a value. Basically there are some ways you can store data in Android :<\/p>\n<ul>\n<li>Shared Preferences: Prrimitive data storage (boolean Strings, ints etc..).<\/li>\n<li>Internal Storage: Device memory storage.<\/li>\n<li>External Storage: Store public data on storage media, like SD cards.<\/li>\n<li>SQLite Database.<\/li>\n<\/ul>\n<p>With\u00a0<a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a>\u00a0we talk about permanent storage about the application. That means that if you uninstall the application, all your data will be lost, so this is application specific. In contrast , SQLite stores structured data in a database, so even when you delete the application the data won&#8217;t be lost.<\/p>\n<p>For this tutorial, we will use the following tools in a Windows 64-bit platform:<\/p>\n<ul>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SKD 4.2<\/li>\n<\/ul>\n<h3>1. Create a new Android Project<\/h3>\n<p>Open Eclipse IDE and go to File -&gt; New -&gt; Project -&gt; Android -&gt; Android Application Project.\u00a0You have to specify the Application Name, the Project Name and the Package name in the appropriate text fields and then click Next.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-new-project-attr5.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3755\" alt=\"create-new-project-attr\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-new-project-attr5.jpg\" width=\"515\" height=\"429\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-new-project-attr5.jpg 515w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-new-project-attr5-300x249.jpg 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><\/p>\n<p>In the next window make sure the \u201cCreate activity\u201d option is selected in order to create a new activity for your project, and click Next. This is optional as you can create a new activity after creating the project, but you can do it all in one step.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/check-create-new-activity9.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3754\" alt=\"check-create-new-activity\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/check-create-new-activity9.jpg\" width=\"517\" height=\"490\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/check-create-new-activity9.jpg 517w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/check-create-new-activity9-300x284.jpg 300w\" sizes=\"(max-width: 517px) 100vw, 517px\" \/><\/a><\/p>\n<p>Select \u201cBlankActivity\u201d and click Next.<\/p>\n<p><a href=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-blanc-activity.jpg\"><img decoding=\"async\" alt=\"create-blanc-activity\" src=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/create-blanc-activity.jpg\" width=\"528\" height=\"502\" \/><\/a><\/p>\n<p>You will be asked to specify some information about the new activity. \u00a0In the Layout Name text field you have to specify the name of the file that will contain the layout description of your app. In our case the file\u00a0<code>res\/layout\/main.xml<\/code>\u00a0will be created. Then, click Finish.<\/p>\n<p><a href=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/new-activity-attr.jpg\"><img decoding=\"async\" alt=\"new-activity-attr\" src=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/new-activity-attr.jpg\" width=\"484\" height=\"455\" \/><\/a><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3>2. Create the main layout of the Application<\/h3>\n<p>Open\u00a0<code>res\/layout\/main.xml<\/code>\u00a0file :<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-xml-file.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3761\" alt=\"main-xml-file\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-xml-file.jpg\" width=\"381\" height=\"528\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-xml-file.jpg 381w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-xml-file-216x300.jpg 216w\" sizes=\"(max-width: 381px) 100vw, 381px\" \/><\/a><\/p>\n<p>And paste the following code :<\/p>\n<pre class=\"brush:java\">&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"\r\n    tools:context=\".MainActivity\" &gt;\r\n\r\n    &lt;CheckBox\r\n        android:id=\"@+id\/checkBox1\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Check Box\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/editText1\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Enter Your Name...\"&gt;\r\n\r\n        &lt;requestFocus \/&gt;\r\n    &lt;\/EditText&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/button1\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Save\" \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;<\/pre>\n<p>Now you may open the Graphical layout editor to preview the User Interface you created:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/graphical-layout3.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3762\" alt=\"graphical-layout\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/graphical-layout3.jpg\" width=\"518\" height=\"554\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/graphical-layout3.jpg 518w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/graphical-layout3-280x300.jpg 280w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><\/a><\/p>\n<h3>3. Code<\/h3>\n<p>Now we have to write the code of the application. Use the Package Explorer to navigate to the Java file of the Activity you\u2019ve created:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-src-file4.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3763\" alt=\"main-src-file\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-src-file4.jpg\" width=\"527\" height=\"307\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-src-file4.jpg 527w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-src-file4-300x174.jpg 300w\" sizes=\"(max-width: 527px) 100vw, 527px\" \/><\/a><\/p>\n<p>The code of this tutorial is very simple. Basically there are two main operations one can perform when using\u00a0SharedPreferences \u00a0in Android. That is store data and load data. You should:<\/p>\n<ul>\n<li>Create a new <code>SharedPreferences<\/code> object.<\/li>\n<li>Then get an <code>Editor<\/code> instance from that object. The <code>Editor<\/code> object will help you manipulate the data that you&#8217;ve stored.<\/li>\n<li>Use\u00a0<code>putString<\/code>, <code>putBoolean<\/code> methods to store a pair key\/value<\/li>\n<li>Use <code>getBoolean<\/code>, <code>getString<\/code> to get the values you want.<\/li>\n<\/ul>\n<pre class=\"brush:java\">package com.javacodegeeks.android.androidsharedpreferences;\r\n\r\nimport android.app.Activity;\r\nimport android.content.SharedPreferences;\r\nimport android.content.SharedPreferences.Editor;\r\nimport android.os.Bundle;\r\nimport android.preference.PreferenceManager;\r\nimport android.view.View;\r\nimport android.view.View.OnClickListener;\r\nimport android.widget.Button;\r\nimport android.widget.CheckBox;\r\nimport android.widget.EditText;\r\n\r\npublic class MainActivity extends Activity implements OnClickListener {\r\n\r\n\tCheckBox checkBox;\r\n\tEditText editText;\r\n\tButton button;\r\n\r\n\t@Override\r\n\tprotected void onCreate(Bundle savedInstanceState) {\r\n\t\t\/\/ TODO Auto-generated method stub\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\t\tsetContentView(R.layout.main);\r\n\r\n\t\tcheckBox = (CheckBox) findViewById(R.id.checkBox1);\r\n\t\teditText = (EditText) findViewById(R.id.editText1);\r\n\t\tbutton = (Button) findViewById(R.id.button1);\r\n\t\tbutton.setOnClickListener(this);\r\n\t\tloadSavedPreferences();\r\n\t}\r\n\r\n\tprivate void loadSavedPreferences() {\r\n\t\tSharedPreferences sharedPreferences = PreferenceManager\r\n\t\t\t\t.getDefaultSharedPreferences(this);\r\n\t\tboolean checkBoxValue = sharedPreferences.getBoolean(\"CheckBox_Value\", false);\r\n\t\tString name = sharedPreferences.getString(\"storedName\", \"YourName\");\r\n\t\tif (checkBoxValue) {\r\n\t\t\tcheckBox.setChecked(true);\r\n\t\t} else {\r\n\t\t\tcheckBox.setChecked(false);\r\n\t\t}\r\n\r\n\t\teditText.setText(name);\r\n\t}\r\n\r\n\tprivate void savePreferences(String key, boolean value) {\r\n\t\tSharedPreferences sharedPreferences = PreferenceManager\r\n\t\t\t\t.getDefaultSharedPreferences(this);\r\n\t\tEditor editor = sharedPreferences.edit();\r\n\t\teditor.putBoolean(key, value);\r\n\t\teditor.commit();\r\n\t}\r\n\r\n\tprivate void savePreferences(String key, String value) {\r\n\t\tSharedPreferences sharedPreferences = PreferenceManager\r\n\t\t\t\t.getDefaultSharedPreferences(this);\r\n\t\tEditor editor = sharedPreferences.edit();\r\n\t\teditor.putString(key, value);\r\n\t\teditor.commit();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void onClick(View v) {\r\n\t\t\/\/ TODO Auto-generated method stub\r\n\t\tsavePreferences(\"CheckBox_Value\", checkBox.isChecked());\r\n\t\tif (checkBox.isChecked())\r\n\t\t\tsavePreferences(\"storedName\", editText.getText().toString());\r\n\r\n\t\tfinish();\r\n\t}\r\n\r\n}<\/pre>\n<h3>4. Run the application<\/h3>\n<p>This is the main screen of our Application.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-screen12.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3759\" alt=\"main-screen\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-screen12.jpg\" width=\"256\" height=\"470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-screen12.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/main-screen12-163x300.jpg 163w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>Now, you can edit your the preferences:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/edit-prefs.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3756\" alt=\"edit-prefs\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/edit-prefs.jpg\" width=\"256\" height=\"470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/edit-prefs.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/edit-prefs-163x300.jpg 163w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>And then press save. When you press save, method\u00a0<code>finish()<\/code> will be executed and the application will exit to the main screen of the emultor.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/emulator-main-screen.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3757\" alt=\"emulator-main-screen\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/emulator-main-screen.jpg\" width=\"256\" height=\"470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/emulator-main-screen.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/emulator-main-screen-163x300.jpg 163w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>Then you can navigate to the emulator and open the application:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/apps.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3753\" alt=\"apps\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/apps.jpg\" width=\"256\" height=\"470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/apps.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/apps-163x300.jpg 163w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>See your saved preferences:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/loaded-prefs.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-3758\" alt=\"loaded-prefs\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/loaded-prefs.jpg\" width=\"256\" height=\"470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/loaded-prefs.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/loaded-prefs-163x300.jpg 163w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<h3>Download Eclipse Project<\/h3>\n<p>This was an Android SavedPreferences Example. Download the Eclipse Project of this tutorial:\u00a0<a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/AndroidSharedPreferences.zip\">AndroidSharedPreferences.zip<\/a><a href=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/AndroidThreadExample.zip\"><br \/>\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a pair : key and a value. Basically there are some ways you can store data in Android : Shared Preferences: Prrimitive data storage (boolean Strings, ints etc..). Internal Storage: Device memory storage. External Storage: &hellip;<\/p>\n","protected":false},"author":4,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[443,444],"tags":[],"class_list":["post-3749","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-content","category-sharedpreferences"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android SharedPreferences Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android SharedPreferences Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-05-19T12:46:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nikos Maravitsas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikos Maravitsas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\"},\"author\":{\"name\":\"Nikos Maravitsas\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/686a494fbb577a8d1231862b139cda6b\"},\"headline\":\"Android SharedPreferences Example\",\"datePublished\":\"2013-05-19T12:46:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\"},\"wordCount\":490,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"articleSection\":[\"content\",\"SharedPreferences\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\",\"name\":\"Android SharedPreferences Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2013-05-19T12:46:52+00:00\",\"description\":\"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"content\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/content\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SharedPreferences\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/content\/sharedpreferences\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android SharedPreferences Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/686a494fbb577a8d1231862b139cda6b\",\"name\":\"Nikos Maravitsas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Nikos-Maravitsas-80x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Nikos-Maravitsas-80x96.jpg\",\"caption\":\"Nikos Maravitsas\"},\"description\":\"Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. During his studies he discovered his interests about software development and he has successfully completed numerous assignments in a variety of fields. Currently, his main interests are system\u2019s security, parallel systems, artificial intelligence, operating systems, system programming, telecommunications, web applications, human \u2013 machine interaction and mobile development.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/nikos-maravitsas\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android SharedPreferences Example - Java Code Geeks","description":"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/","og_locale":"en_US","og_type":"article","og_title":"Android SharedPreferences Example - Java Code Geeks","og_description":"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-05-19T12:46:52+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Nikos Maravitsas","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Nikos Maravitsas","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/"},"author":{"name":"Nikos Maravitsas","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/686a494fbb577a8d1231862b139cda6b"},"headline":"Android SharedPreferences Example","datePublished":"2013-05-19T12:46:52+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/"},"wordCount":490,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","articleSection":["content","SharedPreferences"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/","name":"Android SharedPreferences Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2013-05-19T12:46:52+00:00","description":"In this example we are going to see how to use Android\u00a0SharedPreferences. You can permanently\u00a0store preferences using\u00a0SharedPreferences\u00a0with the form of a","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/content\/android-sharedpreferences-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"content","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/content\/"},{"@type":"ListItem","position":5,"name":"SharedPreferences","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/content\/sharedpreferences\/"},{"@type":"ListItem","position":6,"name":"Android SharedPreferences Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/686a494fbb577a8d1231862b139cda6b","name":"Nikos Maravitsas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Nikos-Maravitsas-80x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Nikos-Maravitsas-80x96.jpg","caption":"Nikos Maravitsas"},"description":"Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. During his studies he discovered his interests about software development and he has successfully completed numerous assignments in a variety of fields. Currently, his main interests are system\u2019s security, parallel systems, artificial intelligence, operating systems, system programming, telecommunications, web applications, human \u2013 machine interaction and mobile development.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/nikos-maravitsas\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=3749"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3749\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=3749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=3749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=3749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}