スレッドのメッセージ ループを実行するために使用されるクラス。デフォルトでは、スレッドにはメッセージ ループが関連付けられていません。これを作成するには、ループを実行するスレッドで prepare() を呼び出し、次に loop() を呼び出して、ループが停止するまでメッセージを処理させます。
メッセージ ループとの対話のほとんどは、Handler クラスを介して行われます。
以下に、スレッドの実行メソッドがあります
@Override
public void run() {
try {
// preparing a looper on current thread
// the current thread is being detected implicitly
Looper.prepare();
Log.i(TAG, "DownloadThread entering the loop");
// now, the handler will automatically bind to the
// Looper that is attached to the current thread
// You don't need to specify the Looper explicitly
handler = new Handler();
// After the following line the thread will start
// running the message loop and will not normally
// exit the loop unless a problem happens or you
// quit() the looper (see below)
Looper.loop();
Log.i(TAG, "DownloadThread exiting gracefully");
} catch (Throwable t) {
Log.e(TAG, "DownloadThread halted due to an error", t);
}
}