0

I have a java statement like this:

int MAX_CACHE_AGE = TimeUnit.DAYS.toMillis(14);

And I want to have a max cache age of 0 when debugging. However, I also want to minimize the complexity of my build. What are some ways I can do this? How do you do this? I am developing for Android so if your method is Android specific, tell my anyway.

4

1 回答 1

3

Initialize this variable in the onCreate() method if it's in an application component, or in the constructor if it's in a normal Java class. The Android tools have a BuildConfig class that is auto generated. You can use its DEBUG field to alter the value.

if(BuildConfig.DEBUG) {
    MAX_CACHE_AGE = TimeUnit.DAYS.toMillis(0);
} else {
    MAX_CACHE_AGE = TimeUnit.DAYS.toMillis(14);
} 
于 2013-03-30T03:16:43.700 回答