Wednesday, April 4, 2012

Eclipse Resource Caching

When I have a number of services that need to be kicked off, I use resources arrays to iterate through them and fire them up. This looks something like this:
 String[] arr = getResources().getStringArray(R.array.downloadServices);  
        for (int i = 0; i < arr.length; i++) {  
           final String serviceName = GlobalConstants.SERVICE_PACKAGE_NAME+ arr[i];  
         
           Intent intent = new Intent( serviceName);  
           startService(intent);  
        }  
Now here's the rub. Sometimes, but not every time, when you generate a build either in debug or production mode, it seems like the resources get cached. So if you've made a change to the arrays.xml for example, the build may not regenerate the R file and the new service won't be a part of the new build.

Easy fix though. Simply run a clean project before doing the build!