1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

StrictMode & android.os.NetworkOnMainThreadException

Posted at

Android 3.0からはStrictModeがデフォルトで有効になっており、UIスレッド上でネットワーク処理を行おうとすると
android.os.NetworkOnMainThreadException という例外が投げられる。

StrictModeを無効にするには後述のコードを書けばいいけれど、テスト以外ではAsyncTaskなどを使いUIスレッド外で処理した方が良いと思う。

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?