Android Global Strings

A global string, or array of strings are declared in an external xml file in the resource folder:<project>/res/values/strings.xml

Declaring a global string

<?xml version="1.0" encoding="utf-8"?>
   <string name="hello">Hello World!
   <string name="app_name">MyTest

Using a global string while creating a TextView

XML example:


Code example:


Getting a global string

String hello = context.getString(R.string.hello);

Global String Array

Declaration in a Global String Array

  <?xml version="1.0" encoding="utf-8"?>
   <string-array name="planets_array">

Code usage

String[] planets =