47
46

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.

[Android] スレッドを止めずに ◯◯ 秒後に △△ するコード

Last updated at Posted at 2015-07-13

メインスレッドで実行する場合は次のようにします。

例)3秒後に実行
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
    @Override
    public void run() {
        // ここに3秒後に実行したい処理
    }
}, 3000);

もしメインスレッドとは別のスレッドで実行させたい場合は次のようにします。

例)3秒後に実行
HandlerThread handlerThread = new HandlerThread("foo");
handlerThread.start();
new Handler(handlerThread.getLooper()).postDelayed(new Runnable() {
    @Override
    public void run() {
        // ここに3秒後に実行したい処理
    }
}, 3000);
47
46
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
47
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?