Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Override android strict mode policy when in android tests to allow calling network on main thread.Useful when you want to access mock web server address and you don't care about the threading.
import android.os.StrictMode
fun <T> withStrictModeThreadPolicy(threadPolicy: StrictMode.ThreadPolicy, block: () -> T): T {
val previousPolicy = StrictMode.getThreadPolicy()
try {
return block()
} finally {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment