private void runInMainThread(Runnable runnable) {
        if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
            mHandler.post(runnable);
        } else {
            runnable.run();
        }
    }
private void runInMainThread ( Runnable runnable ) { if ( Looper . getMainLooper ( ) . getThread ( ) != Thread . currentThread ( ) ) { mHandler . post ( runnable ) ; } else { runnable . run ( ) ; } }
Be sure execute in main thread.

@param runnable code