Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.annotation.TargetApi; import android.os.Build; import android.os.HandlerThread; public class Main { @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static void quitSafely(HandlerThread handlerThread) { if (handlerThread == null) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { handlerThread.quitSafely(); } else { handlerThread.quit(); } } }