Code example for Handler

0
    } 
 
    @Test 
    public void idleMainLooper_executesScheduledTasks() { 
        final boolean[] wasRun = new boolean[]{false};
        new Handler().postDelayed(new Runnable() {
            @Override 
            public void run() { 
                wasRun[0] = true;
            } 
        }, 2000); 
 
        assertFalse(wasRun[0]);
        ShadowLooper.idleMainLooper(1999); 
        assertFalse(wasRun[0]);
        ShadowLooper.idleMainLooper(1); 
        assertTrue(wasRun[0]);
    } 
 
    @Test 
    public void idleConstantly_runsPostDelayedTasksImmediately() {