public void run() { try { if (LOG_ENGINE_TASKS) log.i("running task.work() " + task.getClass().getName()); if (!initialized) throw new IllegalStateException("Engine not initialized"); // run task task.work(); if (LOG_ENGINE_TASKS) log.i("exited task.work() " + task.getClass().getName()); // post success callback mBackgroundThread.postGUI( new Runnable() { public void run() { if (LOG_ENGINE_TASKS) log.i("running task.done() " + task.getClass().getName() + " in gui thread"); task.done(); } }); // } catch ( final FatalError e ) { // TODO: // Handler h = view.getHandler(); // // if ( h==null ) { // View root = view.getRootView(); // h = root.getHandler(); // } // if ( h==null ) { // // // e.handle(); // } else { // h.postAtFrontOfQueue(new Runnable() { // public void run() { // e.handle(); // } // }); // } } catch (final Exception e) { log.e("exception while running task " + task.getClass().getName(), e); // post error callback mBackgroundThread.postGUI( new Runnable() { public void run() { log.e( "running task.fail(" + e.getMessage() + ") " + task.getClass().getSimpleName() + " in gui thread "); task.fail(e); } }); } }
/** * Schedule task for execution in Engine thread * * @param task is task to execute */ public void post(final EngineTask task) { if (LOG_ENGINE_TASKS) log.d("executing task " + task.getClass().getSimpleName()); TaskHandler taskHandler = new TaskHandler(task); mBackgroundThread.postBackground(taskHandler); }