I have the following pieces of code:
1)
int operationCnt = 10;
for (int i = 0; i < operationCnt; i++) { // for every instruction
    final int curOperation = i;
    post(new Runnable() {
        @Override
        public void run() {
            // execute something on the UI thread
            if (curOperation == operationCnt) {
                // Execution has finished RUN THE NEXT PIECE OF CODE SOMEHOW
            }
        }
    })
}
2)
int operationCnt2 = 10;
for (int i = 0; i < operationCnt2; i++) { // for every instruction
    final int curOperation = i;
    post(new Runnable() {
        @Override
        public void run() {
            // execute something on the UI thread
            if (curOperation == operationCnt2) {
                // Execution has finished WRAP IT UP
            }
        }
    })
}
I want to make sure that operation 1 runs first, then right after it finishes operation 2 runs. Finally I'd love to be able to run some code after both have finished.
(I want those two to execute sequentially - strictly one after the other)
In other languages that is easy, but I'm not sure what the cleanest way would be to implement the same logic in Java?
Please shed some light.
Thank you
 
     
    