Note that there are some explanatory texts on larger screens.

plurals
  1. POPerform several tasks synchronously in Android
    primarykey
    data
    text
    <p>I don't know how to elegantly solve the following task:</p> <ol> <li>I have several blocks of code (operation) to execute. </li> <li>Each block can return <code>true</code> of <code>false</code> to indicate that further execution is possible.</li> <li>Inside of each block I have to use asyncronous methods calls (Because Android is completeley asynchronous).</li> </ol> <p>Example of processing operations (not working now as expected):</p> <pre><code> List&lt;Operation&gt; operations = command.getOperations(); for (Operation operation : operations) { Log.d(TAG, "Processing operation: " + operation); OperationResult result = operation.execute(activity); Log.d(TAG, "Operation result is: " + result); if (!result.canContinue()) { break; } } </code></pre> <p>The problem is that inside of the operation I need, for example, display AlertDialog and wait for the input. But after I call <code>dialog.show()</code> my method <code>execute</code> finishes and it returns incorrect result. </p> <p>Example of the button listener, registerd with AlertDialog is below:</p> <pre><code> final OperationResult result = new OperationResult(); final class ButtonListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int id) { switch (id) { case DialogInterface.BUTTON_POSITIVE: { result.setCanContinue(true); } case DialogInterface.BUTTON_NEGATIVE: { dialog.cancel(); result.setCanContinue(false); } } } </code></pre> <p>How should I modify processing of operations to support asynchronous model of Android?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload