Skip to content

StrictMode Library Tutorial

inazaruk edited this page Aug 10, 2012 · 6 revisions

Home


This a small tutorial. If you want to know more about this project click here.

This tutorial shows how to developers can enable StrictMode Viewer to view violations reported by their applications.

Step 1. Download com.robomorphine.strictmode.jar library from Download section.

Step 2. Copy com.robomorphine.strictmode.jar library to your project's libs folder.

Step 3. Create class MyApp which extends android.app.Application:

public class App extends Application {

    private final static String TAG = App.class.getSimpleName();
   
    @Override
    public void onCreate() {        
        if(BuildConfig.DEBUG) {
            StrictModeHelper.setStrictMode(Policy.All.Reset, 
                                           Policy.All.DetectAll,
                                           Policy.All.PenaltyDropBox, //REQUIRED
                                           Policy.Thread.PenaltyFalshScreen,
                                           Policy.All.PenaltyLog);
            
            try{ 
                StrictModeHelper.enableUniqueViolations(true); //REQUIRED
            } catch(PlatformNotSupportedException ex) {
                Log.e(TAG, "Unique violations are not supported.", ex);
            }
        }
    }    
}

Step 4. Make sure AndroidManifest.xml uses MyApp as Application object:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >

   <application ... 
       android:name=".MyApp" > <!-- REQUIRED -->
      ...
   </application>
</manifest>

When this is done, all reported violations will be visible from StrictMode Viewer.

Clone this wiki locally