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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:05:14+00:00 2026-05-23T10:05:14+00:00

For my Android app I’ve the need of defining some keys in a single

  • 0

For my Android app I’ve the need of defining some keys in a single constant, and I think the best way to do it is using a map. But not sure whether that’s really the way to go, and how to do it correctly. As I’m targeting Android, a Bundle may also be an option.

I have a list of keys like:

“h” = “http”

“f” = “ftp”

Basically the program is to read a QR code (to keep that code from growing too big I’m using super-short keys), gets those keys, and has to translate them to something useful, in my case a protocol.

I’m trying to define a constant called KEY_PROTOCOLS, I think this should be a Map, so later I can call something like KEY_PROTOCOLS.get(“f”) to get the protocol that belongs to key “f”.

Other classes should also be able to import this constant, and use it. So this map has to be populated in the class right away.

How can I do this?

  • 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-23T10:05:14+00:00Added an answer on May 23, 2026 at 10:05 am

    If the constant is shared by several classes, and if you want to make sure this map is not cleared or modified by some code, you’d better make it unmodifiable :

    public static final Map<String, String> KEY_PROTOCOLS;
    
    static {
        Map<String, String> map = new HashMap<String, String>();
        map.put("f", "ftp");
        // ...
        KEY_PROTOCOLS = Collections.unmodifiableMap(map);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My android app project need to add a new function of saving the click
My android-app gets List in the one activity, but activity,that contains the LisView for
Every activity within my android app is generated using HTML. When one of the
My android app works on landscape mode. I have a listview that contains some
I have written an Android app (target 3.2) using Eclipse 3.7, I tried to
My Android app reads a huge XML file using Simple XML . Obviously it
My android app is supposed to go through twitter using twitter4j libraries, and return
My Android app needs to populate the ListView using the data from an ArrayList
My Android app sends/retrieves data to/from the user's own PC using HTTP and it's
My Android app is calling .NET web method and it returns a single string.

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.