0

I use sqlite I'm my app to store and retrieve names and and images. I use below code to get names of the images to show in the Recyclerview.

int resID = getResources().getIdentifier(iconName, "drawable", getPackageName());

Here I get this warning

 getIdentifier is discouraged because resource reflection makes it harder to perform build optimizations

what is the replacement for this?

Before that I used image id instead of image name to store it in sqlite but it gets problems if I add or remove images from drawable as soon as project recompile again. So, I figured it out that it's better to store images using image name instead of image id.

Zhiliand
  • 37
  • 4

1 Answers1

1

what is the replacement for this?

Maintain a Map<String, Int> to map your in-database identifiers to R.drawable contents. This has the added value of allowing you to rename your drawable resources without impacting the identifiers that you store in your database.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I used this solution by ( Daniel De León ), worked for me. https://stackoverflow.com/questions/4427608/android-getting-resource-id-from-string/4428288#4428288 – Zhiliand Aug 27 '23 at 14:31