Code example for FutureTask

Methods: runOnMainSync, get

0
     * 
     * @param <R> Type of result to return 
     */ 
    public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable)
            throws Throwable { 
        FutureTask<R> task = new FutureTask<R>(callable);
        getInstrumentation().waitForIdleSync();
        getInstrumentation().runOnMainSync(task);
        try { 
            return task.get();
        } catch (ExecutionException e) {
            // Unwrap the cause of the exception and re-throw it. 
            throw e.getCause();
        } 
    } 
 
    protected void enableJavaScriptOnUiThread(final AwContents awContents) {
        getInstrumentation().runOnMainSync(new Runnable() {
            @Override 
            public void run() { 
                awContents.getContentViewCore().getContentSettings().setJavaScriptEnabled(true);