StrictMode 的 DEVELOPER_MODE 定义
我焦急地等待 StrictMode 的开源版本,以继续我们的平台开发。 Android 博客条目中的示例建议围绕 对于 SDK 开发的 StrictMode 调用
if (DEVELOPER_MODE) {
...
}
,我希望每个应用程序在本地定义此常量。然而,对于平台开发来说,android.util.Config.DEBUG
是确定是否开启此功能的最佳方式吗?
I'm anxiously awaiting the open source release of StrictMode for continuation of our platform development. The sample in the Android blog entry suggests surrounding the StrictMode calls with
if (DEVELOPER_MODE) {
...
}
For SDK development, I'd expect this constant to be locally defined by each application. However, for platform development, is android.util.Config.DEBUG
the best way to determine whether to turn this on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
抱歉,
DEVELOPER_MODE
只是我为博客文章和 Javadoc 选择的任意名称。也许我应该在文档中更清楚地说明这一点。我想象人们会制作自己的硬编码,
private static final boolean DEVELOPER_MODE = false;
...他们手工维护,但看起来像
Config.DEBUG
使用起来会更好。我什至不知道这一点! :)Sorry,
DEVELOPER_MODE
was just an arbitrary name I picked for the blog post and Javadoc. Perhaps I should make that more clear in the docs.I'd imagined people would make their own hard-coded,
private static final boolean DEVELOPER_MODE = false;
... that they maintain by hand, but looks like
Config.DEBUG
would have been a better thing to use. I didn't even know about that! :)Config.DEBUG 不会真正起作用,因为它几乎总是设置为 false。最好查看 AndroidManifest 文件中的 debuggable 属性。我已将其记录在博客文章中。 链接包含此答案
Config.DEBUG is not going to actually works since it is pretty much always set to false. It is better to look at the debuggable attribute in the AndroidManifest file . I have documented it on a blog post. Links are with this answer
回答我自己的问题...
作为平台开发人员(使用 Android 创建设备),每当使用 eng 或 userdebug 构建平台时,Android 中的活动管理器都会自动在系统分区上安装的所有应用程序的主线程上启用 StrictMode。我同意 Manfred 的观点,即 Config.DEBUG 不适合 SDK 开发人员。本质上,编写默认加载在系统分区上的应用程序的平台开发人员无需执行任何操作即可利用 StrictMode - 平台会为他们做到这一点。
To Answer my own question...
As a platform developer (one using Android to create a device), the Activity Manager in Android automatically enables StrictMode on the main thread for all apps installed on the System Partition whenever the platform is built with an eng or userdebug built. I agree with Manfred that Config.DEBUG is not appropriate for SDK developers. Essentially, platform developers writing applications which are loaded by default on the System Partition don't have to do anything to take advantage of StrictMode - the platform does it for them.
这是一个老问题,但我想提一下,我能想到的最接近的替代方案是应用工程师的
BuildConfig.DEBUG
。它返回这是否是调试版本。It's an old question, but I'd like to mention that the closest alternative I can imagine is
BuildConfig.DEBUG
for application engineers. It returns whether this is a debug build.