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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:55:16+00:00 2026-06-04T23:55:16+00:00

I have many shared preference for my app (mostly relating to color customization) and

  • 0

I have many shared preference for my app (mostly relating to color customization) and I’m unsure what the best method is to store/use them at runtime.

Currently I am doing something like this (with more or less preferences depending on the view) in every activity/fragment:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
int buttonbg = settings.getInt("buttonmenu_bg", 0);
int buttontxt = settings.getInt("buttonmenu_txt", 0);
int headerclr = settings.getInt("header", 0);

And then using those to set the various colors in the display. This seems like a lot of overhead to have to call the PreferenceManager each time and go through all that.

So I started looking at creating an application class, reading the preferences in once and using static variables from the application class in the activities/fragment to set the display.

My question is, are there any drawbacks or gotchas to doing this that I should consider before I venture further down the Application class path?

  • 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-06-04T23:55:17+00:00Added an answer on June 4, 2026 at 11:55 pm

    The purpose of the Application class is to store global application state or data (in memory of course), so your approach is correct. I’ve used it multiple times and it works like a charm.

    What I usually do is to create a Map member variable and provide methods for getting and putting values into it, looks like this:

    package com.test;
    ...
    ...
    public class MyApp extends Application{
    
        private Map<String, Object> mData;
    
        @Override
        public void onCreate() {
            super.onCreate();
            mData = new HashMap<String, Object>();
        }
    
        public Object get(String key){
            return mData.get(key);
        }
        public void put(String key,Object value){
            mData.put(key, value);
        }
    }
    

    Then from my activities, I just do ((MyApp) getApplication()).get("key") or ((MyApp) getApplication()).put("key",object). Also, don’t forget to set the android:name attribute in your manifest file, under the application tag:

    <application
            ...
            ...
            android:name="com.test.MyApp"> 
    </application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 'server' program that updates many linked lists in shared memory in
I have many tables that use Lookup/Enum references for most of their column values.
I have many forms that use AJAX (w/ jQuery) for validation and data submission.
We have various servers that have many directories shared. It's easy enough to look
I have used Hibernate in the past and I share many people's frustration with
I have three solutions which build two clients and a server, and share many
I have a table within my database that has many records, some records share
I want to share my session variables in PHP using many subdomains. I have
I have MANY small Test Projects where I put together just enough code to
I have many links in my page. For example <a href=/promotions/download/schools/australia.aspx>Australia</a> Now I want

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.