Hallo dann schaue dir mal die das Beispiel an.
Würde sagen das zweite ist das was du suchst.
https://www.oreilly.com/librar…g/9781449364120/ch04.html
Code
public class LooperActivity extends Activity { LooperThread mLooperThread; private static class LooperThread extends Thread { public Handler mHandler; public void run() { Looper.prepare(); mHandler = new Handler() { public void handleMessage(Message msg) { if(msg.what == 0) { doLongRunningOperation(); } } }; Looper.loop(); } } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLooperThread = new LooperThread(); mLooperThread.start(); } public void onClick(View v) { if (mLooperThread.mHandler != null) { Message msg = mLooperThread.mHandler.obtainMessage(0); mLooperThread.mHandler.sendMessage(msg); } } private void doLongRunningOperation() { // Add long running operation here. } protected void onDestroy() { mLooperThread.mHandler.getLooper().quit(); } }