最好的办法,包括调试code? [英] Best Way to Include Debug Code?
本文介绍了最好的办法,包括调试code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编程Android应用,并在这里的最佳方式可以是或可以不是相同的Java一般
I am programming Android applications, and the best way here may or may not be the same as Java in general.
我只是希望能够设置调试标志,将只执行了code某部分时,它被设置为真 - 当量为C ++设置preprocessor的#define调试和使用的#ifdef DEBUG。
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.
有没有一个公认的或最好的方式做到这一点在Java中?
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.
推荐答案
这是我做的方式:
// in some.class.with.Constants
public static final boolean DEV_MODE = true;
// in some other class
import static some.class.with.Constants.DEV_MODE;
if(DEV_MODE){
Log.d('sometag', 'somemessage');
}
这篇关于最好的办法,包括调试code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文