There is a handler.
h = new Handler(Looper.getMainLooper()) { public void handleMessage(android.os.Message msg){ switch(msg.what){ case 1: // что то выполняется break; case 2: // что то выполняется break; case 3: // что то выполняется break; } }} I send him messages like this:
Thread t = new Thread(new Runnable() { @Override public void run() { for (int i = 1; i <= 100; i++) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } h.sendEmptyMessage(i); }} }); t.start(); in each case the condition is checked, and if it truly would like to be able to stop all subsequent actions. For example, in case 1 condition is true, respectively, case 2 and all subsequent ones will not be fulfilled.
Forgive me if I put it somehow incorrectly, I explain as I understand myself at this stage.