use of android.os.HandlerThread in project chromeview by pwnall.
the class DeviceMotionAndOrientation method getHandler.
private Handler getHandler() {
// use the same polling thread (also see crbug/234282).
synchronized (mHandlerLock) {
if (mHandler == null) {
HandlerThread thread = new HandlerThread("DeviceMotionAndOrientation");
thread.start();
// blocks on thread start
mHandler = new Handler(thread.getLooper());
}
return mHandler;
}
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowContextWrapperTest method sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided.
@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");
}
use of android.os.HandlerThread in project reark by reark.
the class ContentProviderStoreCoreBase method createHandler.
@NonNull
public static Handler createHandler(@NonNull final String name) {
checkNotNull(name);
HandlerThread handlerThread = new HandlerThread(name);
handlerThread.start();
return new Handler(handlerThread.getLooper());
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowLooperTest method schedulerOnAnotherLooper_shouldNotBeMaster_byDefault.
@Test
public void schedulerOnAnotherLooper_shouldNotBeMaster_byDefault() {
HandlerThread ht = getHandlerThread();
assertThat(shadowOf(ht.getLooper()).getScheduler()).isNotSameAs(RuntimeEnvironment.getMasterScheduler());
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowLooperTest method shouldSetNewScheduler_whenLooperIsReset.
@Test
public void shouldSetNewScheduler_whenLooperIsReset() {
HandlerThread ht = getHandlerThread();
Looper looper = ht.getLooper();
ShadowLooper sLooper = shadowOf(looper);
Scheduler old = sLooper.getScheduler();
sLooper.reset();
assertThat(old).isNotSameAs(sLooper.getScheduler());
}
Aggregations