{"id":18456405,"url":"https://github.com/nicosnicolaou16/data-store-setup","last_synced_at":"2026-04-17T02:31:25.910Z","repository":{"id":228351825,"uuid":"769379687","full_name":"NicosNicolaou16/Data-Store-Setup","owner":"NicosNicolaou16","description":"This project demonstrates the setup of the Jetpack Library's Preference Data Store.","archived":false,"fork":false,"pushed_at":"2026-02-27T23:09:05.000Z","size":152,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-28T03:34:31.672Z","etag":null,"topics":["android","android-application","data-store","datastore-android"],"latest_commit_sha":null,"homepage":"https://medium.com/@nicosnicolaou/preferences-data-store-setup-b197e3db09dd","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NicosNicolaou16.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-08T23:34:10.000Z","updated_at":"2026-02-27T23:09:10.000Z","dependencies_parsed_at":"2024-03-18T11:40:32.103Z","dependency_job_id":"fd2b7dfc-70a1-4913-b7e3-4391560364fe","html_url":"https://github.com/NicosNicolaou16/Data-Store-Setup","commit_stats":null,"previous_names":["nicosnicolaou16/data-store-setup"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NicosNicolaou16/Data-Store-Setup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FData-Store-Setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FData-Store-Setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FData-Store-Setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FData-Store-Setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NicosNicolaou16","download_url":"https://codeload.github.com/NicosNicolaou16/Data-Store-Setup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FData-Store-Setup/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31912329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-application","data-store","datastore-android"],"created_at":"2024-11-06T08:11:27.394Z","updated_at":"2026-04-17T02:31:25.883Z","avatar_url":"https://github.com/NicosNicolaou16.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Store Setup\n\n[![Linktree](https://img.shields.io/badge/linktree-1de9b6?style=for-the-badge\u0026logo=linktree\u0026logoColor=white)](https://linktr.ee/nicos_nicolaou)\n[![Site](https://img.shields.io/badge/Site-blue?style=for-the-badge\u0026label=Web)](https://nicosnicolaou16.github.io/)\n[![X](https://img.shields.io/badge/X-%23000000.svg?style=for-the-badge\u0026logo=X\u0026logoColor=white)](https://twitter.com/nicolaou_nicos)\n[![LinkedIn](https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white)](https://linkedin.com/in/nicos-nicolaou-a16720aa)\n[![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge\u0026logo=medium\u0026logoColor=white)](https://medium.com/@nicosnicolaou)\n[![Mastodon](https://img.shields.io/badge/-MASTODON-%232B90D9?style=for-the-badge\u0026logo=mastodon\u0026logoColor=white)](https://androiddev.social/@nicolaou_nicos)\n[![Bluesky](https://img.shields.io/badge/Bluesky-0285FF?style=for-the-badge\u0026logo=Bluesky\u0026logoColor=white)](https://bsky.app/profile/nicolaounicos.bsky.social)\n[![Dev.to blog](https://img.shields.io/badge/dev.to-0A0A0A?style=for-the-badge\u0026logo=dev.to\u0026logoColor=white)](https://dev.to/nicosnicolaou16)\n[![YouTube](https://img.shields.io/badge/YouTube-%23FF0000.svg?style=for-the-badge\u0026logo=YouTube\u0026logoColor=white)](https://www.youtube.com/@nicosnicolaou16)\n[![Google Developer Profile](https://img.shields.io/badge/Developer_Profile-blue?style=for-the-badge\u0026label=Google)](https://g.dev/nicolaou_nicos)\n\nA comprehensive guide and implementation example for setting up **Jetpack Preference DataStore** in Android. This project demonstrates how to handle persistent data using a modern, type-safe, and asynchronous approach.\n\n\u003e [!IMPORTANT]  \n\u003e Check out the full deep-dive article for this setup:  \n\u003e 👉 **[Preferences Data Store Setup - Medium](https://medium.com/@nicosnicolaou/preferences-data-store-setup-b197e3db09dd)** 👈\n\n\n## 🛠️ Implementation Guide\n\n### Step 1:\n\nAdd the dependencies library\n\n#### Kotlin\n\n```Kotlin\nval preferencesDataStoreVersion by extra(\"1.2.0\")\n\ndependencies {\n    //...\n    //Preferences dataStore\n    implementation(\"androidx.datastore:datastore-preferences:$preferencesDataStoreVersion\")\n}\n```\n\n#### libs.versions.toml\n\n```toml\n[versions]\n# other versions here...\ndataStore = \"1.2.0\"\n\n[libraries]\n# other libraries here...\npreference-data-store = { group = \"androidx.datastore\", name = \"datastore-preferences\", version.ref = \"dataStore\" }\n```\n\n#### Application Gradle:\n\n```Kotlin\nimplementation(libs.preference.data.store)\n```\n\n### Step 2:\n\nCreate a Helper class that initialize the Data Store\n\n```Kotlin\nobject PreferencesDataStoreHelper {\n\n    private const val PREFERENCES_DATA_STORE_NAME = \"preferences_data_store_name\"\n\n    private val Context.dataStore: DataStore\u003cPreferences\u003e by preferencesDataStore(name = PREFERENCES_DATA_STORE_NAME)\n\n    //Other Code Here...\n}\n```\n\n### Step 3:\n\nCreate the two methods for save and print and for our example we are using only for String value\n\n```Kotlin\nobject PreferencesDataStoreHelper {\n\n    //Other Code Here...\n\n    internal suspend fun saveStringValue(\n        value: String,\n        key: Preferences.Key\u003cString\u003e,\n        context: Context\n    ) {\n        context.dataStore.edit { saveData -\u003e\n            saveData[key] = value\n        }\n    }\n\n    internal fun getStringValueFlow(key: Preferences.Key\u003cString\u003e, context: Context): Flow\u003cString?\u003e =\n        context.dataStore.data\n            .catch { exception -\u003e\n                when (exception) {\n                    is IOException -\u003e emit(emptyPreferences())\n                    else -\u003e throw exception\n                }\n            }.map { readData -\u003e\n                readData[key]\n            }\n\n    //Other Code Here...\n}\n```\n\n### Step 4:\n\nBonus Part - delete specific value and delete all Data Store values\n\n```Kotlin\nobject PreferencesDataStoreHelper {\n\n    //Other Code Here...\n\n    internal suspend fun removeStringValueWithSpecificKey(\n        key: Preferences.Key\u003cString\u003e,\n        context: Context\n    ) {\n        context.dataStore.edit { it.remove(key) }\n    }\n\n    internal suspend fun removeAllValues(context: Context) {\n        context.dataStore.edit { it.clear() }\n    }\n}\n```\n\n### Step 5:\n\nCall the methods for save, print, delete specific value and all values in the screen\n\n```Kotlin\nclass MainActivity : ComponentActivity() {\n\n    //Other Code Here...\n\n    @Composable\n    fun DataStoreMainView() {\n        val scope = rememberCoroutineScope()\n        val context = LocalContext.current\n\n        Box(contentAlignment = Alignment.Center) {\n            Column {\n                Button(\n                    onClick = {\n                        scope.launch {\n                            /**\n                             * Save the Value\n                             * */\n                            PreferencesDataStoreHelper.saveStringValue(\n                                \"testValue\",\n                                stringPreferencesKey(PREFERENCE_STRING_KEY),\n                                context\n                            )\n                        }\n                    },\n                    modifier = Modifier.width(170.dp)\n                ) {\n                    Text(stringResource(R.string.save_string_value))\n                }\n                Button(\n                    onClick = {\n                        scope.launch {\n                            /**\n                             * Read the Value\n                             * */\n                            PreferencesDataStoreHelper.getStringValueFlow(\n                                stringPreferencesKey(PREFERENCE_STRING_KEY),\n                                context\n                            ).collect {\n                                if (it != null) {\n                                    Toast.makeText(context, it, Toast.LENGTH_SHORT).show()\n                                }\n                            }\n                        }\n                    },\n                    modifier = Modifier.width(170.dp)\n                ) {\n                    Text(stringResource(R.string.print_string_value))\n                }\n                Button(\n                    onClick = {\n                        scope.launch {\n                            /**\n                             * Remove a Specific Value\n                             * */\n                            PreferencesDataStoreHelper.removeStringValueWithSpecificKey(\n                                stringPreferencesKey(PREFERENCE_STRING_KEY),\n                                context\n                            )\n                        }\n                    },\n                    modifier = Modifier.width(170.dp)\n                ) {\n                    Text(stringResource(R.string.remove_specific_value))\n                }\n                Button(\n                    onClick = {\n                        scope.launch {\n                            /**\n                             * Remove all the Values\n                             * */\n                            PreferencesDataStoreHelper.removeAllValues(\n                                context\n                            )\n                        }\n                    },\n                    modifier = Modifier.width(170.dp)\n                ) {\n                    Text(stringResource(R.string.remove_all_values))\n                }\n            }\n        }\n    }\n}\n```\n\n## 🔧 Versioning\n\n- **Data Store Version:** **1.2.0**\n- **Target SDK:** **36**\n- **Minimum SDK:** **29**\n- **Kotlin Version:** **2.3.10**\n- **Gradle Version:** **9.0.1**\n\n## 📚 References \u0026 Resources\n\n- [Android Jetpack DataStore](https://developer.android.com/topic/libraries/architecture/datastore)\n\n## ⭐ Stargazers\n\nIf you enjoy this project, please give it a star!\nCheck out all the stargazers\nhere: [Stargazers on GitHub](https://github.com/NicosNicolaou16/Data-Store-Setup/stargazers)\n\n## 🙏 Support \u0026 Contributions\n\nThis project is actively maintained. Feedback, bug reports, and feature requests are welcome! Please feel free to **open an issue** or submit a **pull request**.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fdata-store-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicosnicolaou16%2Fdata-store-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fdata-store-setup/lists"}