{"id":1410,"date":"2022-09-05T03:43:01","date_gmt":"2022-12-25T10:39:09","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/using-kotlin-android-sharedpreferences-can-be-utilized\/"},"modified":"2024-03-15T12:20:53","modified_gmt":"2024-03-15T12:20:53","slug":"using-kotlin-android-sharedpreferences","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/","title":{"rendered":"Using Kotlin Android SharedPreferences"},"content":{"rendered":"<p>In this tutorial, we will explore how to use SharedPreferences in our Android app by employing Kotlin.<\/p>\n<h2>What does Android SharedPreferences refer to?<\/h2>\n<p>SharedPreferences has been a part of the Android API since API level 1. It serves as an interface for storing, modifying, and deleting data locally. Usually, it is employed for caching user-specific data like login forms. This data is stored in a key-value format and it is possible to have several files for holding SharedPreferences data.<\/p>\n<h2>Option 1:<br \/>\nMethods of SharedPreferences<\/h2>\n<p>Let us examine some crucial techniques for SharedPreferences.<\/p>\n<ul class=\"post-ul\">\n<li>getSharedPreferences(String, int) method is used to retrieve an instance of the SharedPreferences. Here String is the name of the SharedPreferences file and int is the Context passed.<\/li>\n<li>The SharedPreferences.Editor() is used to edit values in the SharedPreferences.<\/li>\n<li>We can call commit() or apply() to save the values in the SharedPreferences file. The <a href=\"https:\/\/developer.android.com\/guide\/fragments\/transactions\">commit<\/a>() saves the values immediately whereas apply() saves the values asynchronously.<\/li>\n<\/ul>\n<h2>Using Kotlin, the values of SharedPreferences can be set and retrieved.<\/h2>\n<p>We have the ability to assign values to our SharedPreference instance using Kotlin by following this approach.<\/p>\n<pre class=\"post-pre\"><code>val sharedPreference =  getSharedPreferences(\"PREFERENCE_NAME\",Context.MODE_PRIVATE)\r\nvar editor = sharedPreference.edit()\r\neditor.putString(\"username\",\"Anupam\")\r\neditor.putLong(\"l\",100L)\r\neditor.commit()\r\n<\/code><\/pre>\n<p>When it comes to obtaining a value:<\/p>\n<pre class=\"post-pre\"><code>sharedPreference.getString(\"username\",\"defaultName\")\r\nsharedPreference.getLong(\"l\",1L)\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655dd4f1cdcf9b6757a01a5e\/11-0.png\" alt=\"android shared preference types\" \/><\/div>\n<h2>One option for paraphrasing the given sentence natively could be:<\/h2>\n<p>Kotlin code that can be used to clear and delete the stored records in SharedPreferences.<\/p>\n<p>By using the clear() and remove(String key) methods, we have the option to either remove a specific value or clear all the values.<\/p>\n<pre class=\"post-pre\"><code>editor.clear()\r\neditor.remove(\"username\")\r\n<\/code><\/pre>\n<p>The modifications made to the editor after the commit or apply are not taken into account. The method described above for saving and retrieving values from a SharedPreference is very similar to what we do in Java. So, where does Kotlin offer its unique benefits? We will explore this by looking at an example Android application.<\/p>\n<h2>The project structure of an Android Kotlin project that utilizes SharedPreferences.<\/h2>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655dd4f1cdcf9b6757a01a5e\/17-0.png\" alt=\"android shared preference kotlin project\" \/><\/div>\n<h3>1. Code for the design structure.<\/h3>\n<p>Here is the code for the activity_main.xml layout file.<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/inUserId\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:hint=\"User ID\"\r\n        android:inputType=\"number\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/inPassword\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_below=\"@+id\/inUserId\"\r\n        android:hint=\"Password\"\r\n        android:inputType=\"textPassword\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnSave\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_below=\"@+id\/inPassword\"\r\n        android:text=\"SAVE USER DATA\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnClear\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentStart=\"true\"\r\n        android:layout_below=\"@+id\/btnSave\"\r\n        android:text=\"CLEAR USER DATA\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnShow\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_below=\"@+id\/inPassword\"\r\n        android:text=\"SHOW\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnShowDefault\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_below=\"@+id\/btnSave\"\r\n        android:text=\"Show Default\" \/&gt;\r\n\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/code><\/pre>\n<h3>The Kotlin code for the main activity.<\/h3>\n<p>Here is the code for the Kotlin class MainActivity.kt.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.androidlysharedpreferences\r\n\r\nimport android.content.Context\r\nimport android.content.SharedPreferences\r\nimport android.support.v7.app.AppCompatActivity\r\nimport android.os.Bundle\r\nimport android.preference.PreferenceManager\r\nimport android.view.View\r\nimport com.scdev.androidlysharedpreferences.PreferenceHelper.defaultPreference\r\nimport com.scdev.androidlysharedpreferences.PreferenceHelper.password\r\nimport com.scdev.androidlysharedpreferences.PreferenceHelper.userId\r\nimport com.scdev.androidlysharedpreferences.PreferenceHelper.clearValues\r\nimport com.scdev.androidlysharedpreferences.PreferenceHelper.customPreference\r\n\r\nimport kotlinx.android.synthetic.main.activity_main.*\r\n\r\nclass MainActivity : AppCompatActivity(), View.OnClickListener {\r\n\r\n    val CUSTOM_PREF_NAME = \"User_data\"\r\n\r\n    override fun onCreate(savedInstanceState: Bundle?) {\r\n        super.onCreate(savedInstanceState)\r\n        setContentView(R.layout.activity_main)\r\n\r\n        btnSave.setOnClickListener(this)\r\n        btnClear.setOnClickListener(this)\r\n        btnShow.setOnClickListener(this)\r\n        btnShowDefault.setOnClickListener(this)\r\n\r\n    }\r\n\r\n    override fun onClick(v: View?) {\r\n        val prefs = customPreference(this, CUSTOM_PREF_NAME)\r\n        when (v?.id) {\r\n            R.id.btnSave -&gt; {\r\n                prefs.password = inPassword.text.toString()\r\n                prefs.userId = inUserId.text.toString().toInt()\r\n            }\r\n            R.id.btnClear -&gt; {\r\n                prefs.clearValues\r\n\r\n            }\r\n            R.id.btnShow -&gt; {\r\n                inUserId.setText(prefs.userId.toString())\r\n                inPassword.setText(prefs.password)\r\n            }\r\n            R.id.btnShowDefault -&gt; {\r\n\r\n                val defaultPrefs = defaultPreference(this)\r\n                inUserId.setText(defaultPrefs.userId.toString())\r\n                inPassword.setText(defaultPrefs.password)\r\n            }\r\n        }\r\n    }\r\n\r\n\r\n}\r\n\r\nobject PreferenceHelper {\r\n\r\n    val USER_ID = \"USER_ID\"\r\n    val USER_PASSWORD = \"PASSWORD\"\r\n\r\n    fun defaultPreference(context: Context): SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)\r\n\r\n    fun customPreference(context: Context, name: String): SharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE)\r\n\r\n    inline fun SharedPreferences.editMe(operation: (SharedPreferences.Editor) -&gt; Unit) {\r\n        val editMe = edit()\r\n        operation(editMe)\r\n        editMe.apply()\r\n    }\r\n\r\n    var SharedPreferences.userId\r\n        get() = getInt(USER_ID, 0)\r\n        set(value) {\r\n            editMe {\r\n                it.putInt(USER_ID, value)\r\n            }\r\n        }\r\n\r\n    var SharedPreferences.password\r\n        get() = getString(USER_PASSWORD, \"\")\r\n        set(value) {\r\n            editMe {\r\n                it.putString(USER_PASSWORD, value)\r\n            }\r\n        }\r\n\r\n    var SharedPreferences.clearValues\r\n        get() = { }\r\n        set(value) {\r\n            editMe {\r\n                it.clear()\r\n            }\r\n        }\r\n}\r\n\r\n\r\n<\/code><\/pre>\n<p>With the help of Kotlin Android Extensions, we can avoid using findViewById for each XML view. In the provided code, we are generating a singleton class using the object keyword. A higher-order function named editMe() is declared as an inline function, which contains the logic for the edit operation. We have defined individual properties for each value. The use of get and set Kotlin properties allows us to fetch and modify the data in the shared preferences. Kotlin has significantly reduced the verbosity of the code, resulting in a cleaner appearance. Moreover, we can enhance its conciseness by utilizing another Kotlin higher-order function demonstrated below.<\/p>\n<pre class=\"post-pre\"><code>fun SharedPreferences.Editor.put(pair: Pair&lt;String, Any&gt;) {\r\n    val key = pair.first\r\n    val value = pair.second\r\n    when(value) {\r\n        is String -&gt; putString(key, value)\r\n        is Int -&gt; putInt(key, value)\r\n        is Boolean -&gt; putBoolean(key, value)\r\n        is Long -&gt; putLong(key, value)\r\n        is Float -&gt; putFloat(key, value)\r\n        else -&gt; error(\"Only primitive types can be stored in SharedPreferences\")\r\n    }\r\n<\/code><\/pre>\n<p>And while assigning the values, we carry out the following actions.<\/p>\n<pre class=\"post-pre\"><code>var SharedPreferences.password\r\n        get() = getString(USER_PASSWORD, \"\")\r\n        set(value) {\r\n            editMe {\r\n                it.put(USER_PASSWORD to value)\r\n            }\r\n        }\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655dd4f1cdcf9b6757a01a5e\/28-0.gif\" alt=\"android shared preferences kotlin app output\" \/><\/div>\n<p>You are able to obtain the source code by clicking on the provided link: AndroidlySharedPreferences.<\/p>\n<p>&nbsp;<\/p>\n<p>More tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/a-class-in-kotlin-that-is-sealed\/\" target=\"_blank\" rel=\"noopener\">A class in Kotlin that is sealed.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/how-can-you-determine-the-standard-deviation-in-r\/\" target=\"_blank\" rel=\"noopener\">How can you determine the standard deviation in R?<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/how-can-a-pandas-dataframe-be-acquired-from-an-api-endpoint-that-lacks-order\/\" target=\"_blank\" rel=\"noopener\">get pandas DataFrame from an API endpoint that lacks order?<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/a-brief-overview-of-jsons-fundamentals\/\" target=\"_blank\" rel=\"noopener\">JSON fundamentals<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/broadcastreceiver-android-tutor\/\" target=\"_blank\" rel=\"noopener\">BroadcastReceiver Example Tutorial on Android<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will explore how to use SharedPreferences in our Android app by employing Kotlin. What does Android SharedPreferences refer to? SharedPreferences has been a part of the Android API since API level 1. It serves as an interface for storing, modifying, and deleting data locally. Usually, it is employed for caching user-specific [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1410","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Kotlin Android SharedPreferences - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Kotlin Android SharedPreferences\" \/>\n<meta property=\"og:description\" content=\"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-25T10:39:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-15T12:20:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655dd4f1cdcf9b6757a01a5e\/11-0.png\" \/>\n<meta name=\"author\" content=\"Jackson Davis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jackson Davis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\"},\"author\":{\"name\":\"Jackson Davis\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/55a10b8b0457c35884c25677889ad350\"},\"headline\":\"Using Kotlin Android SharedPreferences\",\"datePublished\":\"2022-12-25T10:39:09+00:00\",\"dateModified\":\"2024-03-15T12:20:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\"},\"wordCount\":540,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\",\"name\":\"Using Kotlin Android SharedPreferences - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2022-12-25T10:39:09+00:00\",\"dateModified\":\"2024-03-15T12:20:53+00:00\",\"description\":\"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Kotlin Android SharedPreferences\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/55a10b8b0457c35884c25677889ad350\",\"name\":\"Jackson Davis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2fdb47d6df1226e92380d96973782572a97b0675d098bb914410dec348eb5d29?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2fdb47d6df1226e92380d96973782572a97b0675d098bb914410dec348eb5d29?s=96&d=mm&r=g\",\"caption\":\"Jackson Davis\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/jacksondavis\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Kotlin Android SharedPreferences - Blog - Silicon Cloud","description":"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance","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:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/","og_locale":"en_US","og_type":"article","og_title":"Using Kotlin Android SharedPreferences","og_description":"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance","og_url":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2022-12-25T10:39:09+00:00","article_modified_time":"2024-03-15T12:20:53+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655dd4f1cdcf9b6757a01a5e\/11-0.png"}],"author":"Jackson Davis","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Jackson Davis","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/"},"author":{"name":"Jackson Davis","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/55a10b8b0457c35884c25677889ad350"},"headline":"Using Kotlin Android SharedPreferences","datePublished":"2022-12-25T10:39:09+00:00","dateModified":"2024-03-15T12:20:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/"},"wordCount":540,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/","url":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/","name":"Using Kotlin Android SharedPreferences - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2022-12-25T10:39:09+00:00","dateModified":"2024-03-15T12:20:53+00:00","description":"Using Kotlin, the values of SharedPreferences can be set and retrieved.We have the ability to assign values to our SharedPreference instance","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/using-kotlin-android-sharedpreferences\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Kotlin Android SharedPreferences"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/55a10b8b0457c35884c25677889ad350","name":"Jackson Davis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2fdb47d6df1226e92380d96973782572a97b0675d098bb914410dec348eb5d29?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2fdb47d6df1226e92380d96973782572a97b0675d098bb914410dec348eb5d29?s=96&d=mm&r=g","caption":"Jackson Davis"},"url":"https:\/\/www.silicloud.com\/blog\/author\/jacksondavis\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=1410"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1410\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=1410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=1410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=1410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}