Question

I need to store the link to the image, which user has chosen. The sources of the images are files, contact icons and resources' drawables (I need drawables since I provide different images for different resolutions/densities). For the purpose of unification I store it in URI, and consequently this URI may be pointing to a file (file://), to content provider or to resource (android.resource://...). Here is how the URI pointing to drawable with id=2130837534 looks like:

android.resource://my.packagename/2130837534

It works fine unless the ids in R.java are regenerated. So, is there any way to prevent SDK from changing some of the R.java ids values?

Was it helpful?

Solution

No you can't, and shouldn't. If you can describe your problem clearly, there might be some other solution.

Save your resource names in a file, in this way.

icon_profile_1 icon_profile_2

And then when you need the resource ID, do this.

int resID = getResources().getIdentifier("icon_profile_1", "drawable","your_package_name");

Check here(java.lang.String, java.lang.String, java.lang.String)

OTHER TIPS

As R.java is auto-generated it can't be restricted from it's operation, because it will agin be auto-generated when your project is cleaned or compiled.

This is impossible In android because R.java is Autogenrated and you cant do anything for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top