private static void initHandler() {
   if (thread == null
       || !thread.isAlive()
       || thread.isInterrupted()
       || thread.getState() == Thread.State.TERMINATED) {
     thread = new HandlerThread("tpush.working.thread");
     thread.start();
     handler = new Handler(thread.getLooper());
     Log.i("CommonWorkingThread", ">>> Create new working thread." + thread.getId());
   }
 }
Ejemplo n.º 2
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);

    return START_STICKY;
  }