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

  • Home
  • SEARCH
  • 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 995753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:46:13+00:00 2026-05-16T06:46:13+00:00

I have a minimal program that does little more than let me set two

  • 0

I have a minimal program that does little more than let me set two preferences (an int and a String) using Android’s PreferenceActivity. So I have an xml file that defines my preferences, and an activity that extends PreferenceActivity. My main activity has an options menu that launches my preference activity. All of that works great. I can set my preferences and the values are retained during and after my program executes.

Now, in my main activity I want to retrieve those preferences. Should be easy, right? Here’s the code from every sample I’ve ever seen:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int intSetting = prefs.getInt("intSetting", 0);
String strSetting = prefs.getString("strSetting", "");

Problem is, if I break at the getInt() call and step over, my stack looks like this and the app will crash if I continue:

Thread [<3> main] (Suspended)
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2494
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2512
ActivityThread.access$2200(ActivityThread,
ActivityThread$ActivityRecord, Intent)
line: 119
ActivityThread$H.handleMessage(Message)
line: 1863
ActivityThread$H(Handler).dispatchMessage(Message)
line: 99 Looper.loop() line: 123
ActivityThread.main(String[]) line:
4363 Method.invokeNative(Object,
Object[], Class, Class[], Class, int,
boolean) line: not available [native
method] Method.invoke(Object,
Object…) line: 521
ZygoteInit$MethodAndArgsCaller.run()
line: 860 ZygoteInit.main(String[])
line: 618 NativeStart.main(String[])
line: not available [native method]

I’ve tried variations on the parameter passed to getDefaultSharedPreferences(), including:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

…and probably some others in different context (i.e. when accessing preferences from my main activity vs. another activity vs. some function in a class that isn’t an activity. The result is always the same.

I’ve read a dozen Q&A posts on the Web from others with this problem who have solved it by writing code identical to mine, so I don’t expect there’s a solution but if anyone has any ideas, let me know.

  • 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-16T06:46:13+00:00Added an answer on May 16, 2026 at 6:46 am

    You do not show the stack trace. The Thread [<3> main] (Suspended) is useless output from Eclipse. You need to examine the real stack trace, which you should get by allowing Android to continue to the “Force Close” dialog, then looking at LogCat (in your DDMS perspective) for the stack trace.

    My guess is that you have a preference named intSetting but it is not an integer, but that is just a guess. Off the cuff, I cannot think of any of the built-in Preference classes that will store an integer preference, as they mostly store strings.

    Your way of accessing the default SharedPreferences (using this) is correct and should not need to be changed.

    Here is a sample project showing the use of PreferenceActivity and getting the SharedPreferences back.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ie6 does not support png transparency. What should be transparent… May 16, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer No answer, just a note about your approach. ILMerge can… May 16, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer If you have a HeaderTemplate or a FooterTemplate defined, you… May 16, 2026 at 4:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I know that being open source does not necessarily makes a program more/less secure
I have a program that loads a file (anywhere from 10MB to 5GB) a
I have a little math problem. I would like to have a function with
I'm writing an MPI program (Visual Studio 2k8 + MSMPI) that uses Boost::thread to
I may be assigned an Android project, and have minimal experience with Java but
I have a two-thread application: GUI, and some background work. I'm trying to send
I have an form with an Opacity less then 1.0. I have a tooltip
I'd like a response from someone who actually does real-time programming in C# or
Any ideas on this? Is there some kind of a signal queue, or does
I have a bizarre need here, and I am unsure of it's feasibility. I

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.