Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think, the simplest way is to introduce the callback mechanism through listeners. To do so, add a listener interface (e.g., <code>GameListener.java</code>), hold reference to the instance of this interface and invoke its methods in the class, where all your game logic appears (let's say <code>Game.java</code>). Then, let your <code>AppelzActivity</code> implement this interface and show dialog when appropriate callback is called:</p> <p><strong><code>GameListener.java</code></strong>:</p> <pre><code>public interface GameListener { /** * ... * NOTE: may be called on any thread */ public void onRoundFinished(); ... } </code></pre> <p><strong><code>Game.java</code></strong>:</p> <pre><code>public class Game { private GameListener listener; public Game(GameListener listener) { this.listener = listener; } ... //Let's say, round finishes here public void finishRound() { ... listener.onRoundFinished(); } } </code></pre> <p><strong><code>AppelzActivity.java</code></strong>:</p> <pre><code>public class AppelzActivity extends Activity implements GameListener { private static final int DLG_ROUND_FINISHED = 1; ... @Override public void onRoundFinished() { runOnUiThread(new Runnable() { @Override public void run() { showDialog(DLG_ROUND_FINISHED); } }); } @Override protected Dialog onCreateDialog(int id) { Dialog dialog = null; switch (id) { case DLG_ROUND_FINISHED: AlertDialog.Builder builder = new AlertDialog.Builder(this); ... // init your dialog here dialog = builder.create(); break; } return dialog; } } </code></pre>
 

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