Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 941679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:13+00:00 2026-05-15T22:09:13+00:00

In my application,there are some application specific settings, which should be available to me

  • 0

In my application,there are some application specific settings, which should be available to me , next time when my application starts up.

In other words i want the data to be available across the sessions of an application cycle.

Can this be achieved without using database(sqlite).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:09:13+00:00Added an answer on May 15, 2026 at 10:09 pm

    Many applications may provide a way to capture user preferences on the settings of a specific application or an activity. For supporting this, Android provides a simple set of APIs.

    Preferences are typically name value pairs. They can be stored as “Shared Preferences” across various activities in an application (note currently it cannot be shared across processes). Or it can be something that needs to be stored specific to an activity.

    1. Shared Preferences: The shared preferences can be used by all the components (activities, services etc) off the applications.

    2. Activity handled preferences: These preferences can only be used with in the activity and can not be used by other components of the application.

    Shared Preferences:

    The shared preferences are managed with the help of the getSharedPreferences method of the Context class. The preferences are stored in a file, that can be either a custom one (1) or the default file (2).

    (1) Here is how you get the instance when you want to specify the file name

    public static final String PREF_FILE_NAME = "PrefFile";
       SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
    

    MODE_PRIVATE is the operating mode for the preferences. It is the default mode and means the created file will be accessed by only the calling application. Other two mode supported are MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE. In MODE_WORLD_READABLE other application can read the created file but can not modify it. In case of MODE_WORLD_WRITEABLE other applications also have write permissions for the created file.

    (2) The recommended way is to use by the default mode, without specifying the file name:

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    

    Finally, once you have the preferences instance, here is how you can retrieve the stored values from the preferences:

     int storedPreference = preferences.getInt("storedInt", 0);
    

    To store values in the preference file SharedPreference.Editor object has to be used. Editor is the nested interface of the SharedPreference class.

    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt("storedInt", storedPreference); // value to store
    editor.commit();
    

    Editor also support methods like remove() and clear() to delete the preference value from the file.

    Activity Preferences:

    The shared preferences can be used by other application components. But if you do not need to share the preferences with other components and want to have activities private preferences. You can do that with the help of getPreferences() method of the activity. The getPreference method uses the getSharedPreferences() method with the name of the activity class for the preference file name.

    Following is the code to get preferences:

    SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    int storedPreference = preferences.getInt("storedInt", 0);
    

    The code to store values is also same as in case of shared preferences.

    SharedPreferences preferences = getPreference(MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt("storedInt", storedPreference); // value to store
    editor.commit();
    

    You can also use other methods like storing the activity state in database. Note Android also contains a package called android.preference. The package defines classes to implement application preferences UI.

    To see some more examples check Android’s Data Storage post on developers site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say there is some functionality needed for an application under development which could be
i've been playing some time with different builds of my application and there seem
I am developing a Java based desktop application. There are some data generated from
I have one application in which I want to pass data between Pages (Views)
Is there some way to have the Mail Merge capability in my application? Maybe
Is there some way to compile (with the CSC task) a WPF Application with
I am writing WCF service hosted in WinForms application. Is there some way to
I have an application deployed into multiple zones and there are some issues with
I have some trouble with jquery ui-events: In my application, there are some sliders.
In our report generation application, there's some pretty hefty queries that take a considerable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.