If 'res' is a local variable or a member/field of your activity, it's fine 
to use 'res' all over your method/activity.

However, don't make res static/global (if you do and fail to set it to null 
at the appropriate time, you may set yourself up for memory leaks.
Don't give it to other instances of other classes that may store/cache the 
value of 'res' in some place (again, trying to avoid memory leaks).

Calling 'getResources()' is not very expensive. However, to make your code 
more readable, you may want to refactor the call to 'getResources()' into a 
local variable (named 'res' in your case).


On Monday, July 14, 2014 4:26:42 PM UTC-4, sweety fx wrote:
>
> I have a class which calls activity.getResources() in many places.
> So I defined a private variable 
> *private int Resources res;*
>
> in onCreate() I defined the value:* res = activity.getResurces()*
>  and then used *res* in the all the places.
>
> is this best practice to do or call activity.getResources() in all the 
> places.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to