Posts

Showing posts with the label Network retry

Android thread coordination and network retry

While we have no shortage of API's and data-structures on a moderne Android stack and generally should favor those, occasionally we need to resort to low-level Java constructs to get work done - this is particularly true for thread and concurrency stuff. Main thread waiting for background thread On Android, if on background/worker thread, while you need to schedule work for main/UI thread and wait for it to complete before doing other work on background/worker thread: class SomeBackgroundWorker{            final CountDownLatch latch = new CountDownLatch(1);              private void someBackgroundWorkerMethod(){                  // 1) Post work to UI thread              activity.runOnUiThread(new Runnable() {                          @Override public void run() ...