StrictMode.ThreadPolicy.Builder | API reference | Android Developers (original) (raw)
Summary:Ctors | Methods | Inherited Methods
public static final class StrictMode.ThreadPolicy.Builder
extends [Object](/reference/java/lang/Object)
``
Creates [ThreadPolicy](/reference/android/os/StrictMode.ThreadPolicy)
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.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build(); StrictMode.setThreadPolicy(policy);
Summary
Public constructors |
---|
Builder() Creates a Builder that detects nothing and has no violations. |
Builder(StrictMode.ThreadPolicy policy) Initializes a Builder from an existing ThreadPolicy. |
Public methods | |
---|---|
StrictMode.ThreadPolicy | build() Constructs the ThreadPolicy instance. |
StrictMode.ThreadPolicy.Builder | detectAll() Detects everything that's potentially suspect. |
StrictMode.ThreadPolicy.Builder | detectCustomSlowCalls() Enables detection of slow calls. |
StrictMode.ThreadPolicy.Builder | detectDiskReads() Enables detection of disk reads. |
StrictMode.ThreadPolicy.Builder | detectDiskWrites() Enables detection of disk writes. |
StrictMode.ThreadPolicy.Builder | detectExplicitGc() Detects calls to Runtime.gc(). |
StrictMode.ThreadPolicy.Builder | detectNetwork() Enables detection of network operations. |
StrictMode.ThreadPolicy.Builder | detectResourceMismatches() Enables detection of mismatches between defined resource types and getter calls. |
StrictMode.ThreadPolicy.Builder | detectUnbufferedIo() Detects unbuffered input/output operations. |
StrictMode.ThreadPolicy.Builder | penaltyDeath() Crashes the whole process on violation. |
StrictMode.ThreadPolicy.Builder | penaltyDeathOnNetwork() Crashes the whole process on any network usage. |
StrictMode.ThreadPolicy.Builder | penaltyDialog() Shows an annoying dialog to the developer on detected violations, rate-limited to be only a little annoying. |
StrictMode.ThreadPolicy.Builder | penaltyDropBox() Enables detected violations log a stacktrace and timing data to the DropBox on policy violation. |
StrictMode.ThreadPolicy.Builder | penaltyFlashScreen() Flashes the screen during a violation. |
StrictMode.ThreadPolicy.Builder | penaltyListener(Executor executor, StrictMode.OnThreadViolationListener listener) Calls #OnThreadViolationListener.onThreadViolation(Violation) on specified executor every violation. |
StrictMode.ThreadPolicy.Builder | penaltyLog() Logs detected violations to the system log. |
StrictMode.ThreadPolicy.Builder | permitAll() Disables the detection of everything. |
StrictMode.ThreadPolicy.Builder | permitCustomSlowCalls() Disables detection of slow calls. |
StrictMode.ThreadPolicy.Builder | permitDiskReads() Disables detection of disk reads. |
StrictMode.ThreadPolicy.Builder | permitDiskWrites() Disables detection of disk writes. |
StrictMode.ThreadPolicy.Builder | permitExplicitGc() Disables detection of calls to Runtime.gc(). |
StrictMode.ThreadPolicy.Builder | permitNetwork() Disables detection of network operations. |
StrictMode.ThreadPolicy.Builder | permitResourceMismatches() Disables detection of mismatches between defined resource types and getter calls. |
StrictMode.ThreadPolicy.Builder | permitUnbufferedIo() Disables detection of unbuffered input/output operations. |
Inherited methods |
---|
From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Public constructors
Builder
public Builder ()
Creates a Builder that detects nothing and has no violations. (but note that [build()](/reference/android/os/StrictMode.ThreadPolicy.Builder#build%28%29)
will default to enabling [penaltyLog()](/reference/android/os/StrictMode.ThreadPolicy.Builder#penaltyLog%28%29)
if no other penalties are specified)
Builder
public Builder (StrictMode.ThreadPolicy policy)
Initializes a Builder from an existing ThreadPolicy.
Parameters | |
---|---|
policy | StrictMode.ThreadPolicy |
Public methods
detectResourceMismatches
public StrictMode.ThreadPolicy.Builder detectResourceMismatches ()
Enables detection of mismatches between defined resource types and getter calls.
This helps detect accidental type mismatches and potentially expensive type conversions when obtaining typed resources.
For example, a strict mode violation would be thrown when calling [TypedArray.getInt(int, int)](/reference/android/content/res/TypedArray#getInt%28int,%20int%29)
on an index that contains a String-type resource. If the string value can be parsed as an integer, this method call will return a value without crashing; however, the developer should format the resource as an integer to avoid unnecessary type conversion.
Returns | |
---|---|
StrictMode.ThreadPolicy.Builder | This value cannot be null. |
penaltyDeath
public StrictMode.ThreadPolicy.Builder penaltyDeath ()
Crashes the whole process on violation. This penalty runs at the end of all enabled penalties so you'll still get see logging or other violations before the process dies.
Unlike [penaltyDeathOnNetwork()](/reference/android/os/StrictMode.ThreadPolicy.Builder#penaltyDeathOnNetwork%28%29)
, this applies to disk reads, disk writes, and network usage if their corresponding detect flags are set.
Returns | |
---|---|
StrictMode.ThreadPolicy.Builder | This value cannot be null. |