android.os.Handler.getLooper()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中android.os.Handler.getLooper()方法的一些代码示例,展示了Handler.getLooper()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler.getLooper()方法的具体详情如下:
包路径:android.os.Handler
类名称:Handler
方法名:getLooper

Handler.getLooper介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getLooper() {
 return handler.getLooper();
}

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getApplicationLooper() {
 return eventHandler.getLooper();
}

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getLooper() {
 return handler.getLooper();
}

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getApplicationLooper() {
 return handler.getLooper();
}

代码示例来源:origin: facebook/stetho

/**
 * Checks whether the current thread is the same thread that the {@link Handler} is associated
 * with.
 * @return true if the current thread is the same thread that the {@link Handler} is associated
 * with; otherwise false.
 */
public static boolean checkThreadAccess(Handler handler) {
 return Looper.myLooper() == handler.getLooper();
}

代码示例来源:origin: google/ExoPlayer

private void postOrRun(Handler handler, Runnable runnable) {
 if (handler.getLooper() == Looper.myLooper()) {
  runnable.run();
 } else {
  handler.post(runnable);
 }
}

代码示例来源:origin: airbnb/epoxy

@Override
 public void execute(@NonNull Runnable command) {
  // If we're already on the same thread then we can execute this synchronously
  if (Looper.myLooper() == handler.getLooper()) {
   command.run();
  } else {
   handler.post(command);
  }
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getApplicationLooper() {
 return handler.getLooper();
}

代码示例来源:origin: google/ExoPlayer

@Override
public Looper getLooper() {
 return handler.getLooper();
}

代码示例来源:origin: google/cameraview

@Override
protected void onDestroy() {
  super.onDestroy();
  if (mBackgroundHandler != null) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
      mBackgroundHandler.getLooper().quitSafely();
    } else {
      mBackgroundHandler.getLooper().quit();
    }
    mBackgroundHandler = null;
  }
}

代码示例来源:origin: google/ExoPlayer

private void sendMessageToTarget(PlayerMessage message) throws ExoPlaybackException {
 if (message.getHandler().getLooper() == handler.getLooper()) {
  deliverMessage(message);
  if (playbackInfo.playbackState == Player.STATE_READY
    || playbackInfo.playbackState == Player.STATE_BUFFERING) {
   // The message may have caused something to change that now requires us to do work.
   handler.sendEmptyMessage(MSG_DO_SOME_WORK);
  }
 } else {
  handler.obtainMessage(MSG_SEND_MESSAGE_TO_TARGET_THREAD, message).sendToTarget();
 }
}

代码示例来源:origin: aa112901/remusic

@Override
public void onDestroy() {
  super.onDestroy();
  mPlayHandler.removeCallbacksAndMessages(null);
  mPlayHandler.getLooper().quit();
  mPlayHandler = null;
  mProgress.removeCallbacks(mUpdateProgress);
  stopAnim();
}

代码示例来源:origin: robolectric/robolectric

private void unschedule() {
 Handler target = realMessage.getTarget();
 if (target != null && scheduledRunnable != null) {
  shadowOf(target.getLooper()).getScheduler().remove(scheduledRunnable);
  scheduledRunnable = null;
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testRemoveCallbacks() throws Exception {
 Handler handler = new Handler();
 ShadowLooper shadowLooper = shadowOf(handler.getLooper());
 shadowLooper.pause();
 handler.post(scratchRunnable);
 handler.removeCallbacks(scratchRunnable);
 shadowLooper.unPause();
 assertThat(scratchRunnable.wasRun).isFalse();
}

代码示例来源:origin: google/ExoPlayer

/**
 * Runs the provided {@link Runnable} on the main thread, blocking until execution completes or
 * until timeout milliseconds have passed.
 *
 * @param timeoutMs the maximum time to wait in milliseconds.
 * @param runnable The {@link Runnable} to run.
 */
public void runOnMainThread(int timeoutMs, final Runnable runnable) {
 if (Looper.myLooper() == handler.getLooper()) {
  runnable.run();
 } else {
  final ConditionVariable finishedCondition = new ConditionVariable();
  handler.post(
    () -> {
     runnable.run();
     finishedCondition.open();
    });
  assertThat(finishedCondition.block(timeoutMs)).isTrue();
 }
}

代码示例来源:origin: robolectric/robolectric

private void runOnUiThread(Runnable action) {
  // This is meant to emulate the behavior of Activity.runOnUiThread();
  shadowOf(handler.getLooper()).getScheduler().post(action);
 }
}

代码示例来源:origin: robolectric/robolectric

private void runOnUiThread(Runnable action) {
  // This is meant to emulate the behavior of Activity.runOnUiThread();
  shadowOf(handler.getLooper()).getScheduler().post(action);
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided() {
 HandlerThread handlerThread = new HandlerThread("test");
 handlerThread.start();
 Handler handler = new Handler(handlerThread.getLooper());
 assertNotSame(handler.getLooper(), Looper.getMainLooper());
 BroadcastReceiver receiver = broadcastReceiver("Larry");
 contextWrapper.registerReceiver(receiver, intentFilter("foo", "baz"), null, handler);
 assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
 contextWrapper.sendBroadcast(new Intent("foo"));
 assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(1);
 shadowOf(handlerThread.getLooper()).idle();
 assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
 assertThat(transcript).containsExactly("Larry notified of foo");
}

代码示例来源:origin: bumptech/glide

@Test
public void testReleasesResourceIfCancelledOnReady() {
 Looper looper = harness.mainHandler.getLooper();
 Shadows.shadowOf(looper).pause();
 final EngineJob<Object> job = harness.getJob();
 job.start(harness.decodeJob);
 job.cancel();
 job.onResourceReady(harness.resource, harness.dataSource);
 verify(harness.resource).recycle();
}

代码示例来源:origin: facebook/litho

@Test
public void testCreationWithInputs() {
 ComponentTree componentTree =
   mComponentTreeBuilder
     .layoutThreadLooper(mLooper)
     .build();
 assertSameAsInternalState(componentTree, mRoot, "mRoot");
 assertEqualToInternalState(componentTree, true, "mIsLayoutDiffingEnabled");
 assertThat(componentTree.isIncrementalMountEnabled()).isTrue();
 assertThat(mContext.getLogger()).isEqualTo(mComponentsLogger);
 assertThat(mContext.getLogTag()).isEqualTo(mLogTag);
 Handler handler = getInternalState(componentTree, "mLayoutThreadHandler");
 assertThat(mLooper).isSameAs(handler.getLooper());
}

相关文章