问题描述
我有目标的SDK设置为3.2和最小的SDK 2.2,我怎么能在我的应用程序中使用strictmode,我的理解是引进,但不能真正了解如何开始使用它。
I have target sdk set as 3.2 and min sdk as 2.2, how can I use strictmode in my application, as I understand it is introduced but cannot really understand how to start using it.
推荐答案
我的建议是两方面的:
首先,添加一些基本 StrictMode code 到您的的的onCreate()
。这使您可以将StrictMode你的整个应用程序在一个简单的方式(尽管你可以把这个code随时随地进行更加具体的测试)。有很好的样本code。在StrictMode文档。
First, add some baseline StrictMode code to your Application's onCreate()
. This lets you apply StrictMode to your entire app in an easy fashion (though you could put this code anywhere for more specific testing). There's good sample code in the StrictMode docs.
二,欲以StrictMode之前检测的SDK版本。这样一来,你只能使用StrictMode在API版本9或以上 - 如果你不这样做检查,你会崩溃在老版本的Android您的应用程序。您可以通过查看Build.VERSION.SDK_INT.
Second, detect the version of the SDK before trying to use StrictMode. This way, you only use StrictMode in API versions 9 or above - if you don't do this check, you'll crash your app on older versions of Android. You can easily detect the SDK version by looking at Build.VERSION.SDK_INT.
另外,您可能希望只启用StrictMode当你测试。你怎么做,这是你的,虽然我已经在过去写了一个解决方案这一点。
Optionally, you may want to only enable StrictMode when you're testing. How you do this is up to you, though I've written up one solution for this in the past.
这篇关于在Android 2.2的严格模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!