/*
 * *
 *  * This file is part of whereisthat-android
 *  *
 *  * Unless otherwise stated in a separate LICENSE file for this project
 *  * or agreed via contract, all rights reserved by the author.
 *
 */

package com.michael_kuck.android.mkcommons;

import android.os.AsyncTask;

public class Dispatch {

    // TODO: Important, verify this is correct AsyncTask usage!
    public static void toBackground(final Runnable backgroundTask, final Runnable completionTask) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                backgroundTask.run();
                return null;
            }

            @Override
            protected void onPostExecute(final Void aVoid) {
                completionTask.run();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
    }

}

@@ -274,16 +274,69 @@
 yncTask;
+%0Aimport android.os.Handler;%0Aimport android.os.Looper;
 %0A%0Apublic
@@ -811,24 +811,74 @@
 id aVoid) %7B%0A
+                if (completionTask != null) %7B%0A    
             
@@ -895,32 +895,50 @@
 tionTask.run();%0A
+                %7D%0A
             %7D%0A  
@@ -1009,10 +1009,326 @@
 %0A    %7D%0A%0A
+    public static void toMainThread(final Runnable completion) %7B%0A        new Handler(Looper.getMainLooper()).post(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                if (completion != null) %7B%0A                    completion.run();%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A
 %7D%0A

Add convenience method for running tasks on main thread