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());
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowLooperTest method differentThreads_getDifferentLoopers.
@Test
public void differentThreads_getDifferentLoopers() {
HandlerThread ht = getHandlerThread();
assertThat(ht.getLooper()).isNotSameAs(Looper.getMainLooper());
}
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 android by owncloud.
the class OperationsService method onCreate.
/**
* Service initialization
*/
@Override
public void onCreate() {
super.onCreate();
Log_OC.d(TAG, "Creating service");
/// First worker thread for most of operations
HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);
/// Separated worker thread for download of folders (WIP)
thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldReturnNullIfThreadHasNotBeenStarted.
@Test
public void shouldReturnNullIfThreadHasNotBeenStarted() throws Exception {
handlerThread = new HandlerThread("test");
assertNull(handlerThread.getLooper());
}
Aggregations