Search in sources :

Example 36 with HandlerThread

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());
}
Also used : Looper(android.os.Looper) HandlerThread(android.os.HandlerThread) Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Example 37 with HandlerThread

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());
}
Also used : HandlerThread(android.os.HandlerThread) Test(org.junit.Test)

Example 38 with HandlerThread

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");
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 39 with HandlerThread

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);
}
Also used : HandlerThread(android.os.HandlerThread)

Example 40 with HandlerThread

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());
}
Also used : HandlerThread(android.os.HandlerThread) Test(org.junit.Test)

Aggregations

HandlerThread (android.os.HandlerThread)313 Handler (android.os.Handler)149 IntentFilter (android.content.IntentFilter)34 Message (android.os.Message)26 PowerManager (android.os.PowerManager)26 Intent (android.content.Intent)25 Context (android.content.Context)22 Test (org.junit.Test)20 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 Looper (android.os.Looper)13 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Uri (android.net.Uri)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Bundle (android.os.Bundle)8