How To Use String Ressource In Java File In Android Without A Layout
I have a Java class that mainly contains strings. It does not have a layout as it is neither a Fragment nor an Activity. It is more used as an auxilliary class. I would like to ass
Solution 1:
getString(R.string...
is not the same as
Resources.getSystem().getString(android.R.string...
Only the second variant you can use in the static context. Alas, you can get this way only system resources.
If you need to get your own resources, no one-line solution exists. Use https://stackoverflow.com/a/4391811/715269 solution of @Cristian. And notice: it is a very good solution, even more, it is the solution meant to be used by the creators of Android.
Solution 2:
You should be able to get your string with:
Resources.getSystem().getString(R.string.more)
See more here, getString Outside of a Context or Activity
Post a Comment for "How To Use String Ressource In Java File In Android Without A Layout"