Code example for HandlerThread

Methods: getState, isAlive, start

0
 
    } 
 
    public int onStartCommand(Intent intent, int flags, int startId) {
 
        if (!thread.isAlive()) {
            if (thread.getState() == Thread.State.TERMINATED) {
                Log.i(TAG,
                        "Radio thread is in terminated state; creating new instance"); 
                thread = new TxHandlerThread(THREAD_NAME,
                        Process.THREAD_PRIORITY_AUDIO);
            } 
            thread.start();
            Log.i(TAG, "Radio thread started");
            showNotification(); 
        } else { 
            Log.i(TAG, "Radio thread is already alive");
        } 
         
        RadioStatus.setRunning(true);