Search code examples
androidstringgetresource

Calling getResources() ten times Android


so as my question says, I am in a situation where I need to get ten different strings using getResources() and then compare them to a string the user enters.
This is how I'm doing it currently:

if(string == getResources().getString(R.string.x)) 

Since this code is going to be repeated ten times for ten different strings in R.java, I'm wondering if there is going to be a loss in performance by calling getResources() so many times.

Is there an easier solution, like creating an object from getResources() and then getting one string at a time from that object?

Sorry if I'm blabbering, I'm new to this.

Thanks!


Solution

  • Then you can do something like this:

    Resources res = yourContext.getResources();
    //use this res variable instead of getResources() function a small example
    Bitmap bitmap = BitmapFactory.decodeResource(res,R.id.ic_launcher);