Qiita Conference 2025

Qiita史上最多!豪華12名のゲストが登壇

特別講演ゲスト(敬称略)

ymrl、成瀬允宣、鹿野壮、伊藤淳一、uhyo、徳丸浩、ミノ駆動、みのるん、桜庭洋之、tenntenn、けんちょん、こにふぁー

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
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?