Archive for November, 2011

Escaping Angle Brackets in XML in Android

November 20, 2011

Either specify those characters like this:

< = &lt; > = &gt; 

Or use a CDATA section and put those characters inside:

<![CDATA[<]]> <![CDATA[>]]>


Accessing resources in Android

November 20, 2011

In most cases, you need to get hold of the Context object in order to access the resources in the app (the local package). Because Activity extends Context, you can get all the resources accessible from an instance of Context. For example:


or simply


If you want to access the resources in the local package from an object that doesn’t inherit from Context, you need to pass the context object to it somehow. On the other hand, you can access the resources provided by the system (Android) without any context object:

final Resources r = Resources.getSystem();