By Alvin Alexander. Last updated: June 6, 2016
To access a String
resource/value that you’ve defined in an XML file from your Android/Java code, use the Android getString
method, like this:
String prefsKeyTimeBetweenNotifications = getString(R.string.prefsKeyTimeBetweenNotifications);
In this example I’ve defined prefsKeyTimeBetweenNotifications
as a string resource key in a res/values/strings.xml file, like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="prefsKeyTimeBetweenNotifications">timeBetweenNotifications</string> </resources>
As a word of warning, if you don’t use the getString
method you’ll end up retrieving a long
value.