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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:02:12+00:00 2026-05-14T03:02:12+00:00

R class on android has it’s limitations. You can’t use the resources dynamically for

  • 0

R class on android has it’s limitations. You can’t use the resources dynamically for loading audio, pictures or whatever. If you wan’t for example, load a set of audio files for a choosen object you can’t do something like:

R.raw."string-upon-choosen-object"

I’m new to android and at least I didn’t find how you could do that, depending on what objects are choosen or something more dynamic than that. So, I thought about making it dynamic with a little of memory overhead. But, I’m in doubt if it’s worth it or just working different with external resources.

The idea is this:

Modify the ant build xml to execute my own task. This task, is a java program that parses the R.java file building a set of HashMaps with it’s pair (key, value). I have done this manually and It’s working good. So I need some experts voice about it.

This is how I will manage the whole thing:

Generate a base Application class, e.g. MainApplicationResources that builds up all the require methods and attributes. Then, you can access those methods invoking getApplication() and then the desired method.

Something like this:

  package [packageName]

  import android.app.Application;

  import java.util.HashMap;

  public class MainActivityResources extends Application {

      private HashMap<String,Integer> [resNameObj1];
      private HashMap<String,Integer> [resNameObj2];
      ...
      private HashMap<String,Integer> [resNameObjN];

      public MainActivityResources() {
          super();

      [resNameObj1] = new HashMap<String,Integer>();
      [resNameObj1].put("[resNameObj1_Key1]", new Integer([resNameObj1_Value1]));
      [resNameObj1].put("[resNameObj1_Key2]", new Integer([resNameObj1_Value2]));

      [resNameObj2] = new HashMap<String,Integer>();
      [resNameObj2].put("[resNameObj2_Key1]", new Integer([resNameObj2_Value1]));
      [resNameObj2].put("[resNameObj2_Key2]", new Integer([resNameObj2_Value2]));
      ...
      [resNameObjN] = new HashMap<String,Integer>();
      [resNameObjN].put("[resNameObjN_Key1]", new Integer([resNameObjN_Value1]));
      [resNameObjN].put("[resNameObjN_Key2]", new Integer([resNameObjN_Value2]));
      }

      public int get[ResNameObj1](String resourceName) {
          return [resNameObj1].get(resourceName).intValue();
      }

      public int get[ResNameObj2](String resourceName) {
          return [resNameObj2].get(resourceName).intValue();
      }

      ...

      public int get[ResNameObjN](String resourceName) {
          return [resNameObjN].get(resourceName).intValue();
      }
}

The question is:

Will I add too much memory use of the device? Is it worth it?

Regards,

  • 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-14T03:02:12+00:00Added an answer on May 14, 2026 at 3:02 am

    I’m new to android and at least I
    didn’t find how you could do that,
    depending on what objects are choosen
    or something more dynamic than that.

    The Resources class has a getIdentifier() method that will give you the resource ID given the name as a string. This uses reflection, so you would want to cache the results, perhaps using a LinkedHashMap as an LRU cache.

    Is it worth it?

    IMHO, not really. I would just use getIdentifer() or directly use reflection myself. In fact, I have directly used reflection myself (with the LRU cache) to address this issue.

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

Sidebar

Related Questions

Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it
I have an Android class which has a callback from an asynchronous HTTP process,
junit.framework.AssertionFailedError: Class com.android.deviceintelligence.test.Testshutdown has no public constructor TestCase(String name) or TestCase() at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at
Criteria class(http://developer.android.com/reference/android/location/Criteria.html) has power requirement criteria. But clearly not explained how exactly it works.
I have an Android app that has an Application class and I have another
Has anyone ever used the hidden class PackageParser in Android source code with java
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
I published app at the Market and I keep getting error: Exception class: android.content.res.Resources$NotFoundException
can I check programmaticall wheter the android device has tethering activated? I just watched
The Settings app in Android has the following source code: Code The Settings class

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.