Friday, December 4, 2009

Android secrets: 1

- Which type of resource file do you use to avoid hardcoding of strings?
- res/strings.xml
- Which one for the integers?
- Hm...

Google supports res/config.xml to specify integer constants.
Example of code config.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="proxy_port">4000</integer>
</resources>


In Java code you could get it like below:
int port = 
        getResources().getInteger(R.integer.proxy_port);

No comments:

Post a Comment