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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:12+00:00 2026-05-31T13:22:12+00:00

I am creating a library project for a number of android apps. The apps

  • 0

I am creating a library project for a number of android apps.
The apps all have some common functionality that I wish to include in the library project but the library project functions require use of application specific constants

So I am looking for a way to provide the library functions with the names of the constants and allow each app to define them

An example of a specific app constant and how it is used within the library project

public class AppConstants {
    public static final long APP_ID = 6;//Needs to be set for each app
}

public static long getCurrentAppId(Context context) {
    return getLongPreference(context, CURRENT_APP_ID_KEY, AppConstants.APP_ID);
}

This is just one example of approximately 60 constants that need to be defined for each app for a large number of library functions

Obviously I would normally just import/include the project specific app_constants.java file but this is not possible in the library project files as it hasn’t got a clue about the specific applications (rightly so)

So what is the best way to have each specific app override the constants?

Update
I took a long time deciding on which of the superb answers I have been provided with best suited my needs (Thanks everyone) In the end I chose the xml solution. I don’t particularly like it because it clutters up my apps resources and I did seriously consider using the interface solution but the xml solution does work nicely

  • 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-31T13:22:13+00:00Added an answer on May 31, 2026 at 1:22 pm

    Option #1
    Extend your AppConstants class in each project

    Better Option#2
    Use XML resources to define the constants

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <item type="integer" name="app_id" format="integer">6</item>
    </resources>
    

    then you can retrieve them by

    Context.getResources().getInteger(R.integer.app_id);
    

    add the xml file to your resources in each project with only the values you need different

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

Sidebar

Related Questions

I am creating a Control Library project. I have some Cursor files which i
I'm creating some custom components and backing code. I've created a Flex library project
I'm creating a project to house an iPhone library for common code for the
I have a c# library project, that i configured using nhibernate, and I like
I am creating one class library project. Now by default I have one App.Config
I have a standard class library project with a set of classes that I
I am creating solution and inside I have three projects: A WCF Service Library
I am creating a shared library using gcc and suspect that there may be
I have created a RIA services class library project and things are not going
Which library/project is currently usable for creating Facebook applications? This is a followup to

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.