How to use string resource in a Java class in Android?

A class does not have a context and to use a string resource a context is needed. So just call the class from an activity and give a parameter context and within your class constructor just use that context to get the string resource.

In your custom class you need to import the R namespace for the project to get the resource Id.

import com.myrandomapp.R;

Then to get the actual string

context.getString(R.string.COOL_STRING)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)