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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:49:34+00:00 2026-05-25T10:49:34+00:00

I want to have an option set before the Activity is created or at

  • 0

I want to have an “option” set before the Activity is created or at least before it starts. If there is a way to do this via the AndroidManifest? Consider this example where we have a global config class that is used in onCreate to instantiate an object (not fully OO for brevity)

public class Global {
    public static boolean visible = false;
}
public class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // here is where we want the most up-to-date value of visible
        MyObject obj = new MyObject(Global.visible);
    }
}

Obviously in this case “visible” would be “false”. If this were some sort of API library, we would like to provide the option for users to set “visible” to “true”.

Update 1

The objective is to have the global class in a pre-compiled library and have its value set by a developer utilizing the library. I am looking for easiest way for the developer to do this when they create their application; I think the manifest is the probably the way to go but I don’t know how to inject the value for “visible” via the xml. The answers below using preferences are good but only cover the users point-of-view.

Update 2
IMHO using resources works best here.

<bool name="visible">true</bool>
public class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // here is where we want the most up-to-date value of visible
        Resource res = getResource();
        MyObject obj = new MyObject(res.getBoolean(R.bool.visible));
    }
}
  • 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-25T10:49:34+00:00Added an answer on May 25, 2026 at 10:49 am

    I think using SharedPreferences would do what you are looking for, using Global.visible as the default value. Then if the user changes it to true, it will use that value.

    boolean makeVisible = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
      "MyVisiblePreference",
      Global.visible);
    MyObject obj = new MyObject(makeVisible);
    

    To allow the preference to be updatable without re-compiling or setting (through a Preferences activity), you can load the default preference from resources:

    <bool name="MyVisiblePreference">true</bool>
    

    And reference it similarly with:

    boolean makeVisible = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
       "MyVisiblePreference",
       getResources().getBoolean(R.bool.MyVisiblePreference));
    

    If the developer does not set the preference to false, it will default to true (based upon the resources value).

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

Sidebar

Related Questions

I have created a basic class for a customer. I haven't done this before
I know there have been a few threads on this before, but I have
I have a form and I want to add a select location option. How
I have three panes with the InfoPane center option. I want to know how
I have a select html tag, and I want the background-color of the option
I have a easy select tag: <select> <option></option> <option></option> </select> Then I want use
I have asked a question on this before, but again ran into problems and
Edited: I want to set fields name before values? ->setCellValue('A1','ID'); ->setCellValue('B1','Email'); ->setCellValue('C1','Phone'); .... I
I have asked this question before ( here ), however it received no attention
I have a page which has a couple option links that set GET-based parameters

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.