TubeLab-App-Android/torrentStream/src/main/java/com/github/se_bastiaan/torrentstream/utils/ThreadUtils.java

42 lines
1.5 KiB
Java

/*
*
* * This file is part of TorrentStreamer-Android.
* *
* * TorrentStreamer-Android is free software: you can redistribute it and/or modify
* * it under the terms of the GNU Lesser General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * TorrentStreamer-Android is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU Lesser General Public License for more details.
* *
* * You should have received a copy of the GNU Lesser General Public License
* * along with TorrentStreamer-Android. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.github.se_bastiaan.torrentstream.utils;
import android.os.Handler;
import android.os.Looper;
public final class ThreadUtils {
private ThreadUtils() throws InstantiationException {
throw new InstantiationException("This class is not created for instantiation");
}
/**
* Execute the given {@link Runnable} on the ui thread.
*
* @param runnable The runnable to execute.
*/
public static void runOnUiThread(Runnable runnable) {
Thread uiThread = Looper.getMainLooper().getThread();
if (Thread.currentThread() != uiThread) new Handler(Looper.getMainLooper()).post(runnable);
else runnable.run();
}
}