Android APIs
public static final class

StrictMode.VmPolicy.Builder

extends Object
java.lang.Object
   ↳ android.os.StrictMode.VmPolicy.Builder

Class Overview

Creates StrictMode.VmPolicy instances. Methods whose names start with detect specify what problems we should look for. Methods whose names start with penalty specify what we should do when we detect a problem.

You can call as many detect and penalty methods as you like. Currently order is insignificant: all penalties apply to all detected problems.

For example, detect everything and log anything that's found:

 StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder()
     .detectAll()
     .penaltyLog()
     .build();
 StrictMode.setVmPolicy(policy);
 

Summary

Public Constructors
StrictMode.VmPolicy.Builder()
StrictMode.VmPolicy.Builder(StrictMode.VmPolicy base)
Build upon an existing VmPolicy.
Public Methods
StrictMode.VmPolicy build()
Construct the VmPolicy instance.
StrictMode.VmPolicy.Builder detectActivityLeaks()
Detect leaks of Activity subclasses.
StrictMode.VmPolicy.Builder detectAll()
Detect everything that's potentially suspect.
StrictMode.VmPolicy.Builder detectFileUriExposure()
Detect when a file:// Uri is exposed beyond this app.
StrictMode.VmPolicy.Builder detectLeakedClosableObjects()
Detect when an Closeable or other object with a explict termination method is finalized without having been closed.
StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects()
Detect when a BroadcastReceiver or ServiceConnection is leaked during Context teardown.
StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects()
Detect when an SQLiteCursor or other SQLite object is finalized without having been closed.
StrictMode.VmPolicy.Builder penaltyDeath()
Crashes the whole process on violation.
StrictMode.VmPolicy.Builder penaltyDropBox()
Enable detected violations log a stacktrace and timing data to the DropBox on policy violation.
StrictMode.VmPolicy.Builder penaltyLog()
Log detected violations to the system log.
StrictMode.VmPolicy.Builder setClassInstanceLimit(Class klass, int instanceLimit)
Set an upper bound on how many instances of a class can be in memory at once.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StrictMode.VmPolicy.Builder ()

Added in API level 9

public StrictMode.VmPolicy.Builder (StrictMode.VmPolicy base)

Added in API level 11

Build upon an existing VmPolicy.

Public Methods

public StrictMode.VmPolicy build ()

Added in API level 9

Construct the VmPolicy instance.

Note: if no penalties are enabled before calling build, penaltyLog() is implicitly set.

public StrictMode.VmPolicy.Builder detectActivityLeaks ()

Added in API level 11

Detect leaks of Activity subclasses.

public StrictMode.VmPolicy.Builder detectAll ()

Added in API level 9

Detect everything that's potentially suspect.

In the Honeycomb release this includes leaks of SQLite cursors, Activities, and other closable objects but will likely expand in future releases.

public StrictMode.VmPolicy.Builder detectFileUriExposure ()

Added in API level 18

Detect when a file:// Uri is exposed beyond this app. The receiving app may not have access to the sent path. Instead, when sharing files between apps, content:// should be used with permission grants.

public StrictMode.VmPolicy.Builder detectLeakedClosableObjects ()

Added in API level 11

Detect when an Closeable or other object with a explict termination method is finalized without having been closed.

You always want to explicitly close such objects to avoid unnecessary resources leaks.

public StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects ()

Added in API level 16

Detect when a BroadcastReceiver or ServiceConnection is leaked during Context teardown.

public StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects ()

Added in API level 9

Detect when an SQLiteCursor or other SQLite object is finalized without having been closed.

You always want to explicitly close your SQLite cursors to avoid unnecessary database contention and temporary memory leaks.

public StrictMode.VmPolicy.Builder penaltyDeath ()

Added in API level 9

Crashes the whole process on violation. This penalty runs at the end of all enabled penalties so yo you'll still get your logging or other violations before the process dies.

public StrictMode.VmPolicy.Builder penaltyDropBox ()

Added in API level 9

Enable detected violations log a stacktrace and timing data to the DropBox on policy violation. Intended mostly for platform integrators doing beta user field data collection.

public StrictMode.VmPolicy.Builder penaltyLog ()

Added in API level 9

Log detected violations to the system log.

public StrictMode.VmPolicy.Builder setClassInstanceLimit (Class klass, int instanceLimit)

Added in API level 11

Set an upper bound on how many instances of a class can be in memory at once. Helps to prevent object leaks.