76
65

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.

絶対UIスレッドで動作させたい処理の実装方法

Last updated at Posted at 2015-06-03

メモ

post.java
// Handlerにpost()させて呼び出す
// Handler自体はUIスレッド上でインスタンス生成すること
mHandler = new Handler();

// もしくはLooperでメインスレッドを指定して生成
mHandler = new Handler(Looper.getMainLooper());

mHandler.post(new Runnable() {
        @Override
        public void run() {
            // ここに処理
        }
    });
post.java
// 「このViewのためにやるんだ!」っていうのであれば
// 指定のViewにpostするやり方の方が見た目わかりやすいのかもしれない
// (いいのかどうかは不明)
mTextView.post(new Runnable() {
        @Override
        public void run() {
            // ここに処理
        }
    });
post.java
// ActivityのrunOnUiThread()を利用する場合
mActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // ここに処理
        }
    });

現場からは以上です

76
65
2

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
76
65

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?