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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:22:20+00:00 2026-05-27T19:22:20+00:00

Inspired by Magenta’s book Learning Android, I’ve created an Application class for my app:

  • 0

Inspired by Magenta’s book “Learning Android,” I’ve created an Application class for my app:

public class KITAppClass extends Application implements
        OnSharedPreferenceChangeListener {

      private static final String TAG = KITAppClass.class.getSimpleName();
      //private SharedPreferences KITPrefs;
          public SharedPreferences KITPrefs;        
. . .

However, now I’m getting “KITPrefs cannot be resolved” on this line in a different class file that references the SharedPreferences:

allContacts.setSelected(KITPrefs.getBoolean("allContacts", false));

I’m wondering: if the prefs are shared, why were they marked “private” in the example code?
Why is it still not seen, even after I marked it “public”?

If I add “import KITAppClass;” I get virtually paddled with “The import KITAppClass cannot be resolved”

  • 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-27T19:22:21+00:00Added an answer on May 27, 2026 at 7:22 pm

    Try…

    public class KITAppClass extends Application implements
        OnSharedPreferenceChangeListener {
        ...
        protected static SharedPreferences kitPrefs;
        ...
    }
    

    Then access kitPrefs from the Activity (or other) classes in the app (assuming they occupy the same namespace) using, for example…

    KITAppClass.kitPrefs.getBoolean(...);
    

    In saying that, maintaining an instance of a SharedPreferences at the Application class level isn’t nesessary as you can get the SharedPreferences from any Activity at any time. See Using Shared Preferences.

    Also, think twice about actually extending Application unless you really have to and unless you really know what you’re doing with it. In the majority of cases (for simple apps at least) it isn’t necessary. Just because they show you how to do it in a book doesn’t mean you need to do it.

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

Sidebar

Related Questions

Inspired by Apple's LazyTables sample, I've just built myself a class called ImageLoader. It's
Inspired by an SO question. The Attribute class has several overloads for the IsDefined()
Inspired by this CodingHorror article, Protecting Your Cookies: HttpOnly How do you set this
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
Inspired by the MVC storefront the latest project I'm working on is using extension
Inspired by another question asking about the missing Zip function: Why is there no
Inspired by this question , I wanted to try my hand at the latest
Inspired by this question and answer , how do I create a generic permutations
Inspired by the question What’s the simplest way to call Http GET url using
Inspired by this question I began wondering why the following examples are all illegal

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.