Skip to content Skip to sidebar Skip to footer

Strict Mode In Android 2.2

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.

Solution 1:

My suggestion is two-fold:

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.

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.

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.

Solution 2:

Set the Android Manifest to something like this.

<uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="16"android:maxSdkVersion="16"/>

Use the below code in the onCreate Method.

intSDK_INT= android.os.Build.VERSION.SDK_INT;

if (SDK_INT>8){

StrictMode.ThreadPolicypolicy=newStrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy); 

}

Note: Disable the warning as you are already checking which version of the Android is going to use this code.

This Code will be activated if the Android version is higher than Android 2.2

Solution 3:

This is really helpful for How to use StrictMode in App? Check this.. http://mobile.tutsplus.com/tutorials/android/android-sdk_strictmode/

Solution 4:

Refer to the following link on how to use it. Set it up on the onCreate of the relevant component or the Application

Strict Mode

Solution 5:

It helped in resolving the issue by checking the api level and then executing strict mode.

Post a Comment for "Strict Mode In Android 2.2"