I am programming Android applications, and the best way here may or may not be the same as Java in general.
I simply want to be able to set a debug flag that will only execute certain portions of code when it's set to true––equiv to C++ setting a preprocessor #define DEBUG and using #ifdef DEBUG.
Is there an accepted or best way to accomplish this in Java?
Right now I'm just going to set a variable in my Application object, but I don't imagine this is the best way.
Instead of using your own flag, you can use the flag set automatically by ADT, like this:
final static int appFlags = context.getApplicationInfo().flags; final static boolean isDebug = (appFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
The FLAG_DEBUGGABLE
bit is automatically set to true or false, depending on the "debuggable" attribute of the application (set in AndroidManifest.xml). The latest version of ADT (version 8) automatically sets this attribute for you when not exporting a signed package.
Thus, you don't have to remember setting / resetting your own custom flag.
You can read more in this thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With