{"id":36232,"date":"2016-04-28T15:00:17","date_gmt":"2016-04-28T12:00:17","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=36232"},"modified":"2019-04-24T15:54:09","modified_gmt":"2019-04-24T12:54:09","slug":"android-settings-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/","title":{"rendered":"Android Settings Example"},"content":{"rendered":"<p>During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In <em>Android<\/em> we perform this task with the help of <code><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/Preference.html\" target=\"_blank\" rel=\"noopener noreferrer\">Preference<\/a><\/code> APIs. We may also need&nbsp;settings that allow users to modify preferences in app. Thankfully&nbsp;<em>Android<\/em> provides a powerful framework to manage user preferences.<\/p>\n<p>The provided mechanism allows us to show, save and manipulate user\u2019s preferences very easily, it also&nbsp;has support for automatic UI creation. Yes, you read it right,&nbsp;by declaring the type of a user preference, a user interface for manipulating these preferences is automatically generated, without having us to write a single line of code.&nbsp; All we need to do is to simply use it in our app. Doesn&#8217;t it sound cool? Lets start then.\n<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#create_project\">2. Create a New Android Application Project<\/a><\/dt>\n<dt><a href=\"#main_activity\">3. Use MainActivity as Starting Point<\/a><\/dt>\n<dt><a href=\"#preference_activity\">4. The Preference Framework &#8211;&nbsp;PreferenceActivity<\/a><\/dt>\n<dt><a href=\"#preference_fragment\">5. PreferenceFragment and Preference Headers<\/a><\/dt>\n<dt><a href=\"#download\">6. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1.&nbsp;Introduction<\/h2>\n<p>In the Preference Framework we have four components to cover, they are:<\/p>\n<ul>\n<li>Preference Activity or&nbsp;Fragment \u2013 these host the Preference Screen, displaying your settings. We may use any one (Activity or Fragment) as per our requirement.<\/li>\n<li>Preference XML&nbsp;\u2013&nbsp;a&nbsp;xml file defining your settings items.<\/li>\n<li>Preference Headers \u2013 these are lists of subscreens. An xml file defines the Preference Fragments used for the Headers subscreens.<\/li>\n<li>Shared Preference Change Listener \u2013 listens for any changes in the Shared Preference values.<\/li>\n<\/ul>\n<p>So, now we have a brief introduction to the&nbsp;Preference Framework. We would move forward by creating the project.<\/p>\n<h2><a name=\"create_project\"><\/a>2. Create a New Android Application Project<\/h2>\n<p>We will create a simple Android Project as we are used to. There is nothing special or new for this tutorial. We have some screenshots for those who are new to android development, which will definitely help them start with.<\/p>\n<p><figure id=\"attachment_36288\" aria-describedby=\"caption-attachment-36288\" style=\"width: 777px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project.jpg\" rel=\"attachment wp-att-36288\"><img decoding=\"async\" class=\"wp-image-36288 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project.jpg\" width=\"777\" height=\"734\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project.jpg 777w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project-300x283.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project-768x725.jpg 768w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><\/a><figcaption id=\"caption-attachment-36288\" class=\"wp-caption-text\">Figure 1 : Start with specifying company domain and project name.<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36295\" aria-describedby=\"caption-attachment-36295\" style=\"width: 782px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project_target.jpg\" rel=\"attachment wp-att-36295\"><img decoding=\"async\" class=\"wp-image-36295 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project_target.jpg\" alt=\"Select Minimum SDK, click next to continue.\" width=\"782\" height=\"699\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project_target.jpg 782w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project_target-300x268.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/create_project_target-768x686.jpg 768w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/a><figcaption id=\"caption-attachment-36295\" class=\"wp-caption-text\">Figure 2 : Select Minimum SDK, click next to continue.<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36296\" aria-describedby=\"caption-attachment-36296\" style=\"width: 783px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity.jpg\" rel=\"attachment wp-att-36296\"><img decoding=\"async\" class=\"wp-image-36296 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity.jpg\" alt=\"Add an Activity and Continue.\" width=\"783\" height=\"729\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity.jpg 783w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity-300x279.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity-768x715.jpg 768w\" sizes=\"(max-width: 783px) 100vw, 783px\" \/><\/a><figcaption id=\"caption-attachment-36296\" class=\"wp-caption-text\">Figure 3 : Add an Activity and Continue.<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36297\" aria-describedby=\"caption-attachment-36297\" style=\"width: 809px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity_creation.jpg\" rel=\"attachment wp-att-36297\"><img decoding=\"async\" class=\"wp-image-36297 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity_creation.jpg\" alt=\"Provide activity details. Click on Finish to start coding.\" width=\"809\" height=\"647\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity_creation.jpg 809w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity_creation-300x240.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_app_activity_creation-768x614.jpg 768w\" sizes=\"(max-width: 809px) 100vw, 809px\" \/><\/a><figcaption id=\"caption-attachment-36297\" class=\"wp-caption-text\">Figure 4 : Provide activity details. Click on Finish to start coding.<\/figcaption><\/figure><\/p>\n<p>So, now we have our project. We also have the <code>MainActivity<\/code>, which we will use to show the Preference Settings and also as the start point of <code>PreferenceActivity<\/code>.<br \/>\nThe final structure of the created project is shown in the image below.<\/p>\n<p><figure id=\"attachment_36387\" aria-describedby=\"caption-attachment-36387\" style=\"width: 329px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/project_structure.jpg\" rel=\"attachment wp-att-36387\"><img decoding=\"async\" class=\"wp-image-36387 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/project_structure.jpg\" alt=\"Created Project Structure\" width=\"329\" height=\"387\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/project_structure.jpg 329w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/project_structure-255x300.jpg 255w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/a><figcaption id=\"caption-attachment-36387\" class=\"wp-caption-text\">Figure 5 : Created Project Structure<\/figcaption><\/figure><\/p>\n<p>We&#8217;ll have a look at the auto generated <code>MainActivity<\/code> <code>class<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MainActivity.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample;\n\nimport android.os.Bundle;\nimport android.support.design.widget.FloatingActionButton;\nimport android.support.design.widget.Snackbar;\nimport android.support.v7.app.AppCompatActivity;\nimport android.support.v7.widget.Toolbar;\nimport android.view.View;\nimport android.view.Menu;\nimport android.view.MenuItem;\n\npublic class MainActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);\n        setSupportActionBar(toolbar);\n\n        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);\n        fab.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                Snackbar.make(view, \"Replace with your own action\", Snackbar.LENGTH_LONG)\n                        .setAction(\"Action\", null).show();\n            }\n        });\n    }\n\n}\n<\/pre>\n<p>And here is the auto generated <code>xml layout<\/code> files.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>activity_main.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;android.support.design.widget.CoordinatorLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:fitsSystemWindows=\"true\"\n    tools:context=\"com.webege.rivu.myapplication.MainActivity\"&gt;\n\n    &lt;android.support.design.widget.AppBarLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:theme=\"@style\/AppTheme.AppBarOverlay\"&gt;\n\n        &lt;android.support.v7.widget.Toolbar\n            android:id=\"@+id\/toolbar\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"?attr\/actionBarSize\"\n            android:background=\"?attr\/colorPrimary\"\n            app:popupTheme=\"@style\/AppTheme.PopupOverlay\" \/&gt;\n\n    &lt;\/android.support.design.widget.AppBarLayout&gt;\n\n    &lt;include layout=\"@layout\/content_main\" \/&gt;\n\n    &lt;android.support.design.widget.FloatingActionButton\n        android:id=\"@+id\/fab\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"bottom|end\"\n        android:layout_margin=\"@dimen\/fab_margin\"\n        android:src=\"@android:drawable\/ic_dialog_email\" \/&gt;\n\n&lt;\/android.support.design.widget.CoordinatorLayout&gt;<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>content_main.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\n    app:layout_behavior=\"@string\/appbar_scrolling_view_behavior\"\n    tools:context=\"com.webege.rivu.myapplication.MainActivity\"\n    tools:showIn=\"@layout\/activity_main\"&gt;\n\n    &lt;TextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Hello World!\" \/&gt;\n&lt;\/RelativeLayout&gt;<\/pre>\n<p>and here is the primary screen.<\/p>\n<p><figure id=\"attachment_36423\" aria-describedby=\"caption-attachment-36423\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160421-223015_1.jpg\" rel=\"attachment wp-att-36423\"><img decoding=\"async\" class=\"wp-image-36423 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160421-223015_1.jpg\" alt=\"MainActivity\" width=\"256\" height=\"466\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160421-223015_1.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160421-223015_1-165x300.jpg 165w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36423\" class=\"wp-caption-text\">Figure 6 : MainActivity<\/figcaption><\/figure><\/p>\n<h2><a name=\"main_activity\"><\/a>3. Use MainActivity as Starting Point<\/h2>\n<p>There is nothing new in the codes I&#8217;ve pasted above. We will make a slight alteration to this one. As I&nbsp;already told I&#8217;ll use <code>MainActivity<\/code> to show settings. I will also use the <code>FloatingActionButton<\/code> to start the <code>PreferenceActivity<\/code>. So let us first have a little alteration in the layout files and in the code of <code>MainActivity<\/code>. I have simply changed the icon in <code>FloatingActionButton<\/code> to a settings icon in <code>activity_main.xml<\/code>.<\/p>\n<p>In the <code>content_main.xml<\/code>, I&nbsp;have provided id to the <code>TextView<\/code>, so that i&nbsp;can use it in code for showing the preferences in text. I have also removed the <em>Hello World!<\/em> text from there. Here is the final code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>activity_main.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;android.support.design.widget.CoordinatorLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:fitsSystemWindows=\"true\"\n    tools:context=\"com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample.MainActivity\"&gt;\n\n    &lt;android.support.design.widget.AppBarLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:theme=\"@style\/AppTheme.AppBarOverlay\"&gt;\n\n        &lt;android.support.v7.widget.Toolbar\n            android:id=\"@+id\/toolbar\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"?attr\/actionBarSize\"\n            android:background=\"?attr\/colorPrimary\"\n            app:popupTheme=\"@style\/AppTheme.PopupOverlay\" \/&gt;\n\n    &lt;\/android.support.design.widget.AppBarLayout&gt;\n\n    &lt;include layout=\"@layout\/content_main\" \/&gt;\n\n    &lt;android.support.design.widget.FloatingActionButton\n        android:id=\"@+id\/fab\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"bottom|end\"\n        android:layout_margin=\"@dimen\/fab_margin\"\n        android:src=\"@android:drawable\/ic_menu_preferences\" \/&gt;\n\n&lt;\/android.support.design.widget.CoordinatorLayout&gt;<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>content_main.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\n    app:layout_behavior=\"@string\/appbar_scrolling_view_behavior\"\n    tools:context=\"com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample.MainActivity\"\n    tools:showIn=\"@layout\/activity_main\"&gt;\n\n    &lt;TextView\n        android:id=\"@+id\/settingsContent\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\" \/&gt;\n&lt;\/RelativeLayout&gt;<\/pre>\n<p>In the <code>MainActivity<\/code>, I&#8217;ve used <code>SharedPreferences<\/code> to show the settings primarily. Here it is.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>MainActivity.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample;\n\nimport android.content.Intent;\nimport android.content.SharedPreferences;\nimport android.os.Bundle;\nimport android.preference.PreferenceManager;\nimport android.support.design.widget.FloatingActionButton;\nimport android.support.design.widget.Snackbar;\nimport android.support.v7.app.AppCompatActivity;\nimport android.support.v7.widget.Toolbar;\nimport android.view.View;\nimport android.view.Menu;\nimport android.view.MenuItem;\nimport android.widget.TextView;\n\npublic class MainActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);\n        setSupportActionBar(toolbar);\n\n        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);\n        fab.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                Intent modifySettings=new Intent(MainActivity.this,SettingsActivity.class);\n                startActivity(modifySettings);\n            }\n        });\n\n        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);\n\n        StringBuilder builder = new StringBuilder();\n\n        builder.append(\"\\n\" + \"Perform Sync:\\t\" + sharedPrefs.getBoolean(\"perform_sync\", false));\n        builder.append(\"\\n\" + \"Sync Intervals:\\t\" + sharedPrefs.getString(\"sync_interval\", \"-1\"));\n        builder.append(\"\\n\" + \"Name:\\t\" + sharedPrefs.getString(\"full_name\", \"Not known to us\"));\n        builder.append(\"\\n\" + \"Email Address:\\t\" + sharedPrefs.getString(\"email_address\", \"No EMail Address Provided\"));\n        builder.append(\"\\n\" + \"Customized Notification Ringtone:\\t\" + sharedPrefs.getString(\"notification_ringtone\", \"\"));\n        builder.append(\"\\n\\nClick on Settings Button at bottom right corner to Modify Your Prefrences\");\n\n        TextView settingsTextView = (TextView) findViewById(R.id.settingsContent);\n        settingsTextView.setText(builder.toString());\n\n    }\n\n    \n}\n\n<\/pre>\n<p>So as I told, I&#8217;m using <em><code>settingsTextView<\/code><\/em> to show the <code>SharedPreferences<\/code> data. For simplicity I&#8217;m assuming of an application which has background sync. I&#8217;m assuming that the application would allow user to enable or disable the background sync, and also users can specify the sync interval. This application also stores user&#8217;s name and email, and also allows to modify them. It also has an option to customise push notification ringtone.<\/p>\n<p>In the above code I&#8217;ve initialised <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\" target=\"_blank\" rel=\"noopener noreferrer\">SharedPreferences<\/a> with <code>PreferenceManager.getDefaultSharedPreferences(context)<\/code>. I have used <code>getBoolean<\/code> and <code>getString<\/code> methods to read them if they are present and assigned a default value if they are not. There is one more thing, you can easily get from the above code that I&#8217;ve already created another activity <code>SettingsActivity<\/code>, which I&#8217;ve called on the <code>FloatingActionButton<\/code> click event. That <code>FloatingActionButton<\/code> is actually a subclass of <code>PreferenceActivity<\/code>.<\/p>\n<h2><a name=\"preference_activity\"><\/a>4. The Preference Framework &#8211;&nbsp;<a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceActivity.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceActivity<\/a><\/h2>\n<p>So now we have stepped in to the core part of this tutorial. We will go through the steps of creating the <code>SettingsActivity<\/code>, but let us first look at the framework. We will look at the&nbsp;four most common types of Preferences present in this framework.<\/p>\n<ul>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/CheckBoxPreference.html\" target=\"_blank\" rel=\"noopener noreferrer\">CheckBoxPreference<\/a>: Provides checkbox widget functionality. Will store a Boolean value into the <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a>.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/EditTextPreference.html\" target=\"_blank\" rel=\"noopener noreferrer\">EditTextPreference<\/a>: Provides UI for string input dialog. Will store the entered&nbsp;string into the SharedPreferences.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/ListPreference.html\" target=\"_blank\" rel=\"noopener noreferrer\">ListPreference<\/a>: Displays a list of entries as a dialog. The selected preference will store a string into the <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\" target=\"_blank\" rel=\"noopener noreferrer\">SharedPreferences<\/a>.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/RingtonePreference.html\" target=\"_blank\" rel=\"noopener noreferrer\">RingtonePreference<\/a>: Provides UI to&nbsp;choose a ringtone from the device. The selected&nbsp;ringtone\u2019s URI will be persisted as a string into the <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a>.<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceScreen.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceScreen<\/a>: It&nbsp;is the root of a Preference hierarchy. When a <a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceActivity.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceActivity<\/a> points to this, it is not shown but&nbsp;the contained preferences are shown. When it appears inside another preference hierarchy, it is shown and serves as the gateway to another screen of preferences (may be via Dialog or via Intent).<\/li>\n<li><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceCategory.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceCategory<\/a>: It&nbsp;is used to group <code><a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/Preference.html\">Preference<\/a><\/code> objects and provide a disabled (non-selectable) title above the group..<\/li>\n<\/ul>\n<p>So now lets create the <code>preferences.xml<\/code> file in the <code>values<\/code>&#8211;<code>xml<\/code> folder, it will be used in the <code>SettingsActivity<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>preferences.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;PreferenceScreen xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n    &lt;PreferenceCategory\n        android:title=\"Sync Information\"\n        android:key=\"sync_category\"&gt;\n\n        &lt;CheckBoxPreference\n            android:key=\"perform_sync\"\n            android:summary=\"Enable or disable data sync\"\n            android:title=\"Enable Auto Sync\"\n            android:defaultValue=\"true\"\/&gt;\n\n        &lt;ListPreference\n            android:key=\"sync_interval\"\n            android:title=\"Sync interval\"\n            android:summary=\"Define how often sync will be performed\"\n            android:defaultValue=\"1000\"\n            android:entries=\"@array\/updateInterval\"\n            android:entryValues=\"@array\/updateIntervalValues\"\n            android:dependency=\"perform_sync\"\/&gt;\n\n    &lt;\/PreferenceCategory&gt;\n\n    &lt;PreferenceCategory\n        android:title=\"Personal Informations\"\n        android:key=\"personal_category\"&gt;\n\n\n        &lt;EditTextPreference\n            android:key=\"full_name\"\n            android:title=\"Name\"\n            android:summary=\"Enter Your Complete Name\"\n            android:dialogTitle=\"Your Name\"\n            android:dialogMessage=\"Enter Your Complete Name\"\n            android:defaultValue=\"\"\n            android:inputType=\"textCapWords\"\/&gt;\n\n        &lt;EditTextPreference\n            android:key=\"email_address\"\n            android:title=\"Email Address\"\n            android:summary=\"Enter Your Email Address\"\n            android:dialogTitle=\"Enter Your Email Address\"\n            android:dialogMessage=\"Enter Your Email Address\"\n            android:defaultValue=\"\"\n            android:inputType=\"textEmailAddress\"\/&gt;\n\n    &lt;\/PreferenceCategory&gt;\n\n\n    &lt;PreferenceCategory\n        android:title=\"Customisations\"\n        android:key=\"custom_category\"&gt;\n\n\n        &lt;RingtonePreference\n            android:key=\"notification_ringtone\"\n            android:title=\"Notification Ringtone\"\n            android:summary=\"Customise Notification Ringtone for you\"\n            android:dialogTitle=\"Notification Ringtone\"\n            android:dialogMessage=\"Customise Notification Ringtone for you\"\/&gt;\n\n\n\n    &lt;\/PreferenceCategory&gt;\n\n&lt;\/PreferenceScreen&gt;<\/pre>\n<p>I would like to describe a bit. As I&nbsp;already mentioned&nbsp;<a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceScreen.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceScreen<\/a>&nbsp;is the root. Under that I&nbsp;have three&nbsp;<a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceCategory.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceCategory<\/a>&nbsp;groups, that are&nbsp;sync_category (Sync Information),&nbsp;personal_category (Personal Informations) and&nbsp;custom_category (Customisations).<\/p>\n<p>The provided user settings are already discussed. So we would move forward and create the&nbsp;<a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceActivity.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceActivity<\/a>. Please follow the screenshots.<\/p>\n<p><figure id=\"attachment_36645\" aria-describedby=\"caption-attachment-36645\" style=\"width: 714px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_activity.jpg\"><img decoding=\"async\" class=\"wp-image-36645 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_activity.jpg\" alt=\"Create new Empty Activity\" width=\"714\" height=\"726\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_activity.jpg 714w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_activity-295x300.jpg 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/new_activity-70x70.jpg 70w\" sizes=\"(max-width: 714px) 100vw, 714px\" \/><\/a><figcaption id=\"caption-attachment-36645\" class=\"wp-caption-text\">Figure 7 : Create new Empty Activity<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36646\" aria-describedby=\"caption-attachment-36646\" style=\"width: 804px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Settings.jpg\"><img decoding=\"async\" class=\"wp-image-36646 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Settings.jpg\" alt=\"SettingsActivity Creation\" width=\"804\" height=\"650\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Settings.jpg 804w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Settings-300x243.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Settings-768x621.jpg 768w\" sizes=\"(max-width: 804px) 100vw, 804px\" \/><\/a><figcaption id=\"caption-attachment-36646\" class=\"wp-caption-text\">Figure 8 : Provide Activity Name<\/figcaption><\/figure><\/p>\n<p>So the <code>SettingsActivity<\/code> is created. We will now add a code to this newly created <code>Activity<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SettingsActivity.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample;\n\nimport android.preference.PreferenceActivity;\nimport android.os.Bundle;\n\npublic class SettingsActivity extends PreferenceActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        addPreferencesFromResource(R.xml.preferences);\n    }\n}\n\n\n<\/pre>\n<p>That set. We are done. We will now look at the output screenshots.<\/p>\n<p><figure id=\"attachment_36670\" aria-describedby=\"caption-attachment-36670\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070132_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36670 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070132_jcg.jpg\" alt=\"Initial Screen\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070132_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070132_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36670\" class=\"wp-caption-text\">Figure 9 : Initial Screen<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36671\" aria-describedby=\"caption-attachment-36671\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070138_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36671 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070138_jcg.jpg\" alt=\"PreferenceScreen\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070138_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070138_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36671\" class=\"wp-caption-text\">Figure 10 : PreferenceScreen<\/figcaption><\/figure>[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36672\" aria-describedby=\"caption-attachment-36672\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070144_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36672 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070144_jcg.jpg\" alt=\"Auto Sync (CheckBoxPreference) disabled\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070144_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070144_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36672\" class=\"wp-caption-text\">Figure 11 : Auto Sync (CheckBoxPreference) disabled<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36674\" aria-describedby=\"caption-attachment-36674\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070153.jpg\"><img decoding=\"async\" class=\"wp-image-36674 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070153.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070153.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070153-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36674\" class=\"wp-caption-text\">Figure 12 : Sync Interval (ListPreference)<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36675\" aria-describedby=\"caption-attachment-36675\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070225_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36675 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070225_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070225_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070225_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36675\" class=\"wp-caption-text\">Figure 13 : Name (EditTextPreference)<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36676\" aria-describedby=\"caption-attachment-36676\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070301_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36676 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070301_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070301_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070301_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36676\" class=\"wp-caption-text\">Figure 14 : Email (EditTextPreference, android:inputType=&#8221;textEmailAddress&#8221;)<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36677\" aria-describedby=\"caption-attachment-36677\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070317_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36677 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070317_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070317_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070317_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36677\" class=\"wp-caption-text\">Figure 15 : Notification Ringtone (RingtonePreference)<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36678\" aria-describedby=\"caption-attachment-36678\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070345_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36678 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070345_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070345_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160426-070345_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36678\" class=\"wp-caption-text\">Figure 16 : Final Screen &#8211; All Details<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<h2><a name=\"preference_fragment\"><\/a>5.&nbsp;<a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceFragment.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceFragment<\/a> and Preference Headers<\/h2>\n<p>Till now we have dealt with the simplest example of using Preference Framework. Its time to dive deeper. Sometime you may wish to have separate subscreens for each type of preferences. You may also want a multipane layout Tablets. These requirements can be fulfilled by the use of <code>Preference Headers<\/code> and <code>PreferenceFragment<\/code>&nbsp;.<\/p>\n<p>As I&nbsp;stated in the start of the tutorial that <a href=\"http:\/\/developer.android.com\/reference\/android\/preference\/PreferenceFragment.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreferenceFragment<\/a> is also used to host the PreferenceScreen as the <code>PreferenceActivity<\/code>. Preference Headers sre used to organise the Preference Screens in subscreens. So we are creating another activity <code>SettingsActivity2<\/code>. We will implement <code>preference_header<\/code> and <code>PreferenceFragment<\/code> in this <code>activity<\/code>. First we need to create 4 xml files. 3 for three Preference Screens and 1 for Preference Header. So lets get a glimpse on code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pref_headers.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false\">&lt;preference-headers xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n\n    &lt;!-- These settings headers are only used on tablets. --&gt;\n\n    &lt;header\n        android:fragment=\"com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample.SettingsActivity2$GeneralPreferenceFragment\"\n        android:icon=\"@drawable\/ic_info_black_24dp\"\n        android:title=\"@string\/pref_header_general\"&gt;\n        &lt;extra android:name=\"settings\" android:value=\"prefs_general\" &gt;&lt;\/extra&gt;\n    &lt;\/header&gt;\n\n    &lt;header\n        android:fragment=\"com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample.SettingsActivity2$GeneralPreferenceFragment\"\n        android:icon=\"@drawable\/ic_notifications_black_24dp\"\n        android:title=\"@string\/pref_header_notifications\" &gt;\n        &lt;extra android:name=\"settings\" android:value=\"prefs_notification\" &gt;&lt;\/extra&gt;\n    &lt;\/header&gt;\n\n    &lt;header\n        android:fragment=\"com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample.SettingsActivity2$GeneralPreferenceFragment\"\n        android:icon=\"@drawable\/ic_sync_black_24dp\"\n        android:title=\"@string\/pref_header_data_sync\" &gt;\n        &lt;extra android:name=\"settings\" android:value=\"prefs_sync\" &gt;&lt;\/extra&gt;\n    &lt;\/header&gt;\n\n&lt;\/preference-headers&gt;<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>pref_general.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;PreferenceScreen xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n\n    &lt;EditTextPreference\n        android:key=\"full_name\"\n        android:title=\"Name\"\n        android:summary=\"Enter Your Complete Name\"\n        android:dialogTitle=\"Your Name\"\n        android:dialogMessage=\"Enter Your Complete Name\"\n        android:defaultValue=\"\"\n        android:inputType=\"textCapWords\"\/&gt;\n\n    &lt;EditTextPreference\n        android:key=\"email_address\"\n        android:title=\"Email Address\"\n        android:summary=\"Enter Your Email Address\"\n        android:dialogTitle=\"Enter Your Email Address\"\n        android:dialogMessage=\"Enter Your Email Address\"\n        android:defaultValue=\"\"\n        android:inputType=\"textEmailAddress\"\/&gt;\n\n&lt;\/PreferenceScreen&gt;<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>pref_notification.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;PreferenceScreen xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n\n    &lt;!-- A 'parent' preference, which enables\/disables child preferences (below)\n         when checked\/unchecked. --&gt;\n    &lt;SwitchPreference\n        android:defaultValue=\"true\"\n        android:key=\"notifications_new_message\"\n        android:title=\"@string\/pref_title_new_message_notifications\" \/&gt;\n    \n    &lt;RingtonePreference\n        android:key=\"notification_ringtone\"\n        android:title=\"Notification Ringtone\"\n        android:summary=\"Customise Notification Ringtone for you\"\n        android:dialogTitle=\"Notification Ringtone\"\n        android:dialogMessage=\"Customise Notification Ringtone for you\"\n        android:dependency=\"notifications_new_message\"\/&gt;\n\n\n\n&lt;\/PreferenceScreen&gt;\n\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>pref_data_sync.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;PreferenceScreen xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n\n    &lt;!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to\n         dismiss it. --&gt;\n    &lt;!-- NOTE: ListPreference's summary should be set to its value by the activity code. --&gt;\n    &lt;CheckBoxPreference\n        android:key=\"perform_sync\"\n        android:summary=\"Enable or disable data sync\"\n        android:title=\"Enable Auto Sync\"\n        android:defaultValue=\"true\"\/&gt;\n\n    &lt;ListPreference\n        android:key=\"sync_interval\"\n        android:title=\"Sync interval\"\n        android:summary=\"Define how often sync will be performed\"\n        android:defaultValue=\"1000\"\n        android:entries=\"@array\/updateInterval\"\n        android:entryValues=\"@array\/updateIntervalValues\"\n        android:dependency=\"perform_sync\"\/&gt;\n\n&lt;\/PreferenceScreen&gt;\n<\/pre>\n<p>So before moving to newly created <code>SettingsActivity2<\/code> let me explain the <code>xml<\/code> files first. The <span style=\"text-decoration: underline;\"><em>pref_headers.xml<\/em><\/span> file contains the Headers with <em>Titles<\/em>, <em>Icons<\/em> and target <em>fragments<\/em>. When <code>SettingsActivity2<\/code> is created the Headers will be displayed and upon click of a header item the respective <code>PreferenceScreen<\/code> will be displayed. The <code>&lt;extra&gt;<\/code> is used to pass some arguments to the fragment, which we can get by calling <code>getArguments()<\/code> inside the <code>Fragment<\/code>.<\/p>\n<p>I&#8217;ve divided the previous <em>preferences.xml<\/em> into 3 separate files, namely <em>pref_general.xml<\/em>, <em>pref_notification.xml<\/em> and <em>pref_data_sync.xml<\/em>. Everything in those files are almost same with previous, except a <code>SwitchPreference<\/code> used in <em>pref_notification.xml<\/em>. the functionality of <code>SwitchPreference<\/code> is almost same with <code>CheckBoxPreference<\/code> except that the <code>SwitchPreference<\/code> provides a <code>Switch<\/code> UI instead of <code>CheckBox<\/code> UI. Each of the <code>PreferenceScreen<\/code>s are displayed with <code>PreferenceFragment<\/code>. So here is the new activity code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SettingsActivity2.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.examples.rivu.chakraborty.androidsettingsexample;\n\n\nimport android.annotation.TargetApi;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.content.res.Configuration;\nimport android.media.Ringtone;\nimport android.media.RingtoneManager;\nimport android.net.Uri;\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.preference.ListPreference;\nimport android.preference.Preference;\nimport android.preference.PreferenceActivity;\nimport android.support.v7.app.ActionBar;\nimport android.preference.PreferenceFragment;\nimport android.preference.PreferenceManager;\nimport android.preference.RingtonePreference;\nimport android.text.TextUtils;\nimport android.view.MenuItem;\nimport android.widget.Toast;\n\nimport java.util.List;\n\npublic class SettingsActivity2 extends AppCompatPreferenceActivity {\n\n    \/**\n     * Helper method to determine if the device has an extra-large screen. For\n     * example, 10\" tablets are extra-large.\n     *\/\n    private static boolean isLargeTablet(Context context) {\n        return (context.getResources().getConfiguration().screenLayout\n                &amp; Configuration.SCREENLAYOUT_SIZE_MASK) &gt;= Configuration.SCREENLAYOUT_SIZE_LARGE;\n    }\n\n\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setupActionBar();\n    }\n\n    @Override\n    public boolean onOptionsItemSelected(MenuItem item) {\n        int id = item.getItemId();\n        if (id == android.R.id.home) {\n            onBackPressed();\n            return true;\n        }\n        return super.onOptionsItemSelected(item);\n    }\n\n    \/**\n     * Set up the {@link android.app.ActionBar}, if the API is available.\n     *\/\n    private void setupActionBar() {\n        ActionBar actionBar = getSupportActionBar();\n        if (actionBar != null) {\n            \/\/ Show the Up button in the action bar.\n            actionBar.setDisplayHomeAsUpEnabled(true);\n        }\n    }\n\n    \/**\n     * {@inheritDoc}\n     *\/\n    @Override\n    public boolean onIsMultiPane() {\n        return isLargeTablet(this);\n    }\n\n    \/**\n     * {@inheritDoc}\n     *\/\n    @Override\n    @TargetApi(Build.VERSION_CODES.HONEYCOMB)\n    public void onBuildHeaders(List&lt;Header&gt; target) {\n        loadHeadersFromResource(R.xml.pref_headers, target);\n    }\n\n    \/**\n     * This method stops fragment injection in malicious applications.\n     * Make sure to deny any unknown fragments here.\n     *\/\n    protected boolean isValidFragment(String fragmentName) {\n        return PreferenceFragment.class.getName().equals(fragmentName)\n                || GeneralPreferenceFragment.class.getName().equals(fragmentName);\n    }\n\n\n    @TargetApi(Build.VERSION_CODES.HONEYCOMB)\n    public static class GeneralPreferenceFragment extends PreferenceFragment {\n        @Override\n        public void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n            int preferenceFile_toLoad=-1;\n            String settings = getArguments().getString(\"settings\");\n            if (\"prefs_general\".equalsIgnoreCase(settings)) {\n                \/\/ Load the preferences from an XML resource\n                preferenceFile_toLoad= R.xml.pref_general;\n            }else if (\"prefs_notification\".equalsIgnoreCase(settings)) {\n                \/\/ Load the preferences from an XML resource\n                preferenceFile_toLoad=R.xml.pref_notification;\n            }else if (\"prefs_sync\".equals(settings)) {\n                \/\/ Load the preferences from an XML resource\n                preferenceFile_toLoad=R.xml.pref_data_sync;\n            }\n\n            addPreferencesFromResource(preferenceFile_toLoad);\n\n\n        }\n\n\n\n    }\n\n\n}\n\n\n<\/pre>\n<p>The headers are loaded using <code>loadHeadersFromResource(R.xml.pref_headers, target)<\/code> inside <code>onBuildHeaders<\/code> method. And as per our previous discussions, I&nbsp;have loaded the <code>PreferenceScreen<\/code> for each header in <code>GeneralPreferenceFragment<\/code>. In <code>GeneralPreferenceFragment<\/code><\/p>\n<p>I&#8217;ve first determined the required <code>PreferenceScreen<\/code> using <code>getArguments().getString(\"settings\")<\/code> (which were passed in <em>pref_headers.xml<\/em> using <code>&lt;extra&gt;<\/code> tag), then initialised with <code>addPreferencesFromResource(preferenceFile_toLoad)<\/code>.<\/p>\n<p>There is another new method in <code>SettingsActivity2<\/code>, <code>onIsMultiPane<\/code> which is called internally to determine multipane is required or not. I&#8217;ve returned true if the device is Large Tablet. So lets have a look at the final output screenshots.<\/p>\n<p><figure id=\"attachment_36702\" aria-describedby=\"caption-attachment-36702\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141745_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36702 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141745_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141745_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141745_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36702\" class=\"wp-caption-text\">Figure 17 : Main Settings Page<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36703\" aria-describedby=\"caption-attachment-36703\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141816_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36703 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141816_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141816_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141816_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36703\" class=\"wp-caption-text\">Figure 18 : General Settings<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36704\" aria-describedby=\"caption-attachment-36704\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141823_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36704 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141823_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141823_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141823_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36704\" class=\"wp-caption-text\">Figure 19 : Notification Settings<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36705\" aria-describedby=\"caption-attachment-36705\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141829_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36705 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141829_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141829_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-141829_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36705\" class=\"wp-caption-text\">Figure 20 : Data Sync Settings<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_36706\" aria-describedby=\"caption-attachment-36706\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-145438_jcg.jpg\"><img decoding=\"async\" class=\"wp-image-36706 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-145438_jcg.jpg\" width=\"256\" height=\"455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-145438_jcg.jpg 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/Screenshot_20160427-145438_jcg-169x300.jpg 169w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-36706\" class=\"wp-caption-text\">Figure 21 : Multipane Layout<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<h2><a name=\"download\"><\/a>6. Download the Source Code<\/h2>\n<p>This was an example on Android Settings.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/AndroidSettingsExample.zip\">AndroidSettingsExample<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task with the help of Preference APIs. We may also need&nbsp;settings that allow users to modify preferences in app. Thankfully&nbsp;Android provides a powerful framework to manage user preferences. The provided mechanism allows us to &hellip;<\/p>\n","protected":false},"author":33,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1463],"tags":[],"class_list":["post-36232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-settings"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Settings Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task\" \/>\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\/ui\/settings\/android-settings-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Settings Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-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:author\" content=\"https:\/\/www.facebook.com\/rivu.chakraborty.71\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-28T12:00:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T12:54:09+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=\"Rivu Chakraborty\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rivuchakraborty\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rivu Chakraborty\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 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\/ui\/settings\/android-settings-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/\"},\"author\":{\"name\":\"Rivu Chakraborty\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/214edc4dc73377704682e116fd060db8\"},\"headline\":\"Android Settings Example\",\"datePublished\":\"2016-04-28T12:00:17+00:00\",\"dateModified\":\"2019-04-24T12:54:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/\"},\"wordCount\":1603,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"articleSection\":[\"Settings\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/\",\"name\":\"Android Settings Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2016-04-28T12:00:17+00:00\",\"dateModified\":\"2019-04-24T12:54:09+00:00\",\"description\":\"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-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\/ui\/settings\/android-settings-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\":\"ui\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Settings\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/settings\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android Settings 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\/214edc4dc73377704682e116fd060db8\",\"name\":\"Rivu Chakraborty\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Rivu-Chakraborty_avatar_1418728715-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Rivu-Chakraborty_avatar_1418728715-96x96.jpg\",\"caption\":\"Rivu Chakraborty\"},\"description\":\"Rivu Chakraborty is a Google Certified Android Developer, Sr. Tech Member of Institute of Engineers (India), he also have certifications on Scrum. He is also an author of multiple books on Kotlin, Reactive Programming, Functional Programming and Android Development, published by renowned publication houses. Having total 5+ years of experience he is presently working as a Sr. Software Engineer (Android) at Indus Net Technologies Pvt. Ltd. Rivu Chakraborty considers himself a Kotlin and Android enthusiast and a Kotlin evangelist. He has been using Kotlin since December 2015, so he has around 2 years' experience in Kotlin. As part of his mission to expand the use and knowledge of the Kotlin Language as much as possible, he created the KotlinKolkata User Group, one of the most active Kotlin user groups throughout the world and he is a Founder Organizer of KotlinKolkata. He is also an active member of GDG Kolkata and gives talks at GDG Kolkata Meetups.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/www.facebook.com\/rivu.chakraborty.71\",\"https:\/\/in.linkedin.com\/in\/rivuchk\",\"https:\/\/x.com\/@rivuchakraborty\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/rivu-chakraborty\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Settings Example - Java Code Geeks","description":"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task","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\/ui\/settings\/android-settings-example\/","og_locale":"en_US","og_type":"article","og_title":"Android Settings Example - Java Code Geeks","og_description":"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/rivu.chakraborty.71","article_published_time":"2016-04-28T12:00:17+00:00","article_modified_time":"2019-04-24T12:54:09+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":"Rivu Chakraborty","twitter_card":"summary_large_image","twitter_creator":"@rivuchakraborty","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rivu Chakraborty","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/"},"author":{"name":"Rivu Chakraborty","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/214edc4dc73377704682e116fd060db8"},"headline":"Android Settings Example","datePublished":"2016-04-28T12:00:17+00:00","dateModified":"2019-04-24T12:54:09+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/"},"wordCount":1603,"commentCount":3,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","articleSection":["Settings"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/","name":"Android Settings Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2016-04-28T12:00:17+00:00","dateModified":"2019-04-24T12:54:09+00:00","description":"During the development of mobile applications,&nbsp;a common&nbsp;requirement is of storing app related data to the phone. In Android we perform this task","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/settings\/android-settings-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\/ui\/settings\/android-settings-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":"ui","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/"},{"@type":"ListItem","position":5,"name":"Settings","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/settings\/"},{"@type":"ListItem","position":6,"name":"Android Settings 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\/214edc4dc73377704682e116fd060db8","name":"Rivu Chakraborty","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Rivu-Chakraborty_avatar_1418728715-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Rivu-Chakraborty_avatar_1418728715-96x96.jpg","caption":"Rivu Chakraborty"},"description":"Rivu Chakraborty is a Google Certified Android Developer, Sr. Tech Member of Institute of Engineers (India), he also have certifications on Scrum. He is also an author of multiple books on Kotlin, Reactive Programming, Functional Programming and Android Development, published by renowned publication houses. Having total 5+ years of experience he is presently working as a Sr. Software Engineer (Android) at Indus Net Technologies Pvt. Ltd. Rivu Chakraborty considers himself a Kotlin and Android enthusiast and a Kotlin evangelist. He has been using Kotlin since December 2015, so he has around 2 years' experience in Kotlin. As part of his mission to expand the use and knowledge of the Kotlin Language as much as possible, he created the KotlinKolkata User Group, one of the most active Kotlin user groups throughout the world and he is a Founder Organizer of KotlinKolkata. He is also an active member of GDG Kolkata and gives talks at GDG Kolkata Meetups.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/www.facebook.com\/rivu.chakraborty.71","https:\/\/in.linkedin.com\/in\/rivuchk","https:\/\/x.com\/@rivuchakraborty"],"url":"https:\/\/examples.javacodegeeks.com\/author\/rivu-chakraborty\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/36232","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\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=36232"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/36232\/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=36232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=36232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=36232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}