Refine search
private static synchronized Looper getDefaultLayoutThreadLooper() { if (sDefaultLayoutThreadLooper == null) { final HandlerThread defaultThread = new HandlerThread(DEFAULT_LAYOUT_THREAD_NAME, DEFAULT_BACKGROUND_THREAD_PRIORITY); defaultThread.start(); sDefaultLayoutThreadLooper = defaultThread.getLooper(); } return sDefaultLayoutThreadLooper; }
protected synchronized Looper getLooper(int type){ if (mHandlerThread != null) { mHandlerThread.quit(); mHandlerThread = null; } int priority; switch (type) { case THREAD_TYPE_MAIN_THREAD: return Looper.getMainLooper(); case THREAD_TYPE_HIGH_PRIORITY: priority = android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY; break; case THREAD_TYPE_LOW_PRIORITY: priority = android.os.Process.THREAD_PRIORITY_LOWEST; break; case THREAD_TYPE_NORMAL_PRIORITY: default: priority = android.os.Process.THREAD_PRIORITY_DEFAULT; break; } String threadName = "DFM Handler Thread #"+priority; mHandlerThread = new HandlerThread(threadName, priority); mHandlerThread.start(); return mHandlerThread.getLooper(); }
private void stopBackgroundThread() { if (Build.VERSION.SDK_INT > 17) { backgroundThread.quitSafely(); } else backgroundThread.quit(); try { backgroundThread.join(); } catch (InterruptedException e) { Log.e(TAG, "stopBackgroundThread: ", e); } finally { backgroundThread = null; backgroundHandler = null; } }
public class MyClass { private Handler mBgHandler; public MyClass() { HandlerThread bgThread = new HandlerThread("My-Background-Handler"); bgThread.start(); mBgHandler = new Handler(bgThread.getLooper()); } }
@Override public void onMediaPeriodCreated(int windowIndex, MediaPeriodId mediaPeriodId) { Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); lastCreatedMediaPeriod.set(mediaPeriodId); }
@Test public void shouldStopThreadIfLooperIsQuit() throws Exception { handlerThread = new HandlerThread("test1"); handlerThread.start(); Looper looper = handlerThread.getLooper(); assertFalse(shadowOf(looper).quit); looper.quit(); handlerThread.join(); assertFalse(handlerThread.isAlive()); assertTrue(shadowOf(looper).quit); handlerThread = null; }
@Test public void shouldQuitLooperAndThread() throws Exception { handlerThread = new HandlerThread("test"); Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); handlerThread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); handlerThread.start(); assertTrue(handlerThread.isAlive()); assertTrue(handlerThread.quit()); handlerThread.join(); assertFalse(handlerThread.isAlive()); handlerThread = null; }
/** * This method initializes the aysnc screenshot saving logic */ private void initScreenShotSaver() { if(screenShotSaverThread == null || screenShotSaver == null) { screenShotSaverThread = new HandlerThread("ScreenShotSaver"); screenShotSaverThread.start(); screenShotSaver = new ScreenShotSaver(screenShotSaverThread); } }
@Test public void shouldCallOnLooperPrepared() throws Exception { final Boolean[] wasCalled = new Boolean[] { false }; final CountDownLatch latch = new CountDownLatch(1); handlerThread = new HandlerThread("test") { @Override protected void onLooperPrepared() { wasCalled[0] = true; latch.countDown(); } }; handlerThread.start(); try { assertNotNull(handlerThread.getLooper()); latch.await(1, TimeUnit.SECONDS); assertTrue(wasCalled[0]); } finally { handlerThread.quit(); } }
@Test public void shouldReturnNullIfThreadHasNotBeenStarted() throws Exception { handlerThread = new HandlerThread("test"); assertNull(handlerThread.getLooper()); }
void shutdown() { statsThread.quit(); }
private synchronized void stopDraw() { if (handler != null) { handler.quit(); handler = null; } HandlerThread handlerThread = this.mHandlerThread; mHandlerThread = null; if (handlerThread != null) { try { handlerThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } handlerThread.quit(); } }
/** * Attempts to stop the working task, halts the processing of waiting tasks, and returns a list * of the tasks that were awaiting execution. These tasks are drained (removed) from the task * queue upon return from this method. */ public List<BaseDownloadTask> shutdown() { synchronized (finishCallback) { if (workingTask != null) { pause(); } final List<BaseDownloadTask> unDealTaskList = new ArrayList<>(pausedList); pausedList.clear(); mHandler.removeMessages(WHAT_NEXT); mHandlerThread.interrupt(); mHandlerThread.quit(); return unDealTaskList; } }
/** * Stops the background thread and its {@link Handler}. */ private void stopBackgroundThread() { mBackgroundThread.quitSafely(); try { mBackgroundThread.join(); mBackgroundThread = null; mBackgroundHandler = null; } catch (InterruptedException e) { e.printStackTrace(); } }
@Override protected void onDestroy() { handlerThread.quitSafely(); super.onDestroy(); }
HandlerThread handlerThread = new HandlerThread("ht"); handlerThread.start(); Looper looper = handlerThread.getLooper(); Handler handler = new Handler(looper); context.registerReceiver(receiver, filter, null, handler); // Will not run on main thread
@Override public void onLoadCanceled( int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); }
private HandlerThread getHandlerThread() { HandlerThread ht = new HandlerThread(testName.getMethodName()); ht.start(); return ht; }
/** * Releases the helper. Should be called when the helper is no longer required. */ public void release() { handlerThread.quit(); }