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 6193449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:07:22+00:00 2026-05-24T03:07:22+00:00

have been away from Android for more than a year, trying to pick up

  • 0

have been away from Android for more than a year, trying to pick up on it again, but confused about having a simple default preference.

My app relies heavily on a SQLite3 db, which has hundreds of tables. The launch activity has to build and load a good amount of data at launch.

I just need a simple way to read two strings from a preferences file. The thing is that I want to have, the very first time the application opens, two default string values.

If the user changes that I will save back to it.

Been reading two books, SharedPreferences, File I/O, etc. just that all the examples seem a tad complicated for what I need.

So, If I create a res/pref/preferences.xml all I have seen around are PreferenceScreens as the root element

For my need, I think I just need a root preference such as:

<?xml version="1.0" encoding="utf-8"?>
<Preference
 xmlns:android="http://schemas.android.com/apk/res/android">
</Preference>

how do I add two simple string key/value pairs that I would read at the very first launch, and only when needed write to it?

any help is appreciated, sorry for the noob’iness

  • 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-24T03:07:23+00:00Added an answer on May 24, 2026 at 3:07 am

    I think you’re over complicating what you need to do, sharedpreferences are perfect for this situation, and easily implemented. Just do the check in the onCreate() when the app starts 🙂

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    //"Hello World" is the name of your preferences
    SharedPreferences settings = getSharedPreferences("HelloWorld", 0);
    
    //to get a value from pref - (NAME_OF_PREF,RETURN_IF_NOT_FOUND)
    boolean enteredDetails = settings.getBoolean("details", false);
    string foo = settings.getString("foo_name","no name");
    
    //to write to them - (NAME_OF_PREF,VALUE)
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("foo_name", "Joe Bloggs");
    editor.putBoolean("details", true);
    editor.commit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'e been programming Java forever, but have been away from it for a while.
I'm writing my first location based android app, but got confused about some of
I've been away from web design/development for a long, long now and have recently
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been studying the file system related classes of Adobe AIR 1.5, but so
I have been working on a web services related project for about the last
I have an app that is available from the Android Market. Some users have
First of all this is homework. I have been trying to get rid of
I have been using JustCode(latest ver) for about 2 months now, and have started
I have been making a threaded comment system as a way to learn php

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.