Use getResources () instead of getIdentifier (). Thus, you can get your resource by its name, even if its identifier changes. Here is an example:
int resID = getResources().getIdentifier("nameofthedrawable", "drawable", "com.your.project");
Then you can save only the ressource name in the database and retrieve data from the database later.
See the link for more details.
source share