[Kryonet] Handling the 'connecting' time - progress dialog or something

Hello!

I have an app with a menu with 4 options. I need to make that when you click a button, it checks if Kryo is connected and if not - pop a ProgressDialog and try to reconnect.

I don’t have any idea how this should be done. Tried with AsyncTask (I know how Async works, don’t worry), but I don’t know how it should be handled with my classes.

I have this menu class (it’s the main class in the app) where I call:

  makeConnection = new MakeConnection(this);
        makeConnection.start();


MakeConnection
is a class that connects to the server:

public class MakeConnection extends Thread {
    public Client client;
    public Context context;


    public MakeConnection(Context ctx){
        this.context = ctx;

    }

    @Override
    public void run() {
        client = new Client(9000000,9000000);
        new Thread(client).start();
        
        Network.register(client);

        client.addListener(new Listener.ThreadedListener(new Listener() {
            public void connected (Connection connection) {
            }

            public void received (Connection connection, Object object) {
       
           /*     if (object instanceof Network.PlayerPosition) {
                    Network.PlayerPosition pp = ((PlayerPosition)object);
                    gameLoop.player_opponent.x = pp.x;
                    gameLoop.player_opponent.y = pp.y;
               
                }*/


            }

            public void disconnected (Connection connection) {
                System.exit(0);
            }
        }));

        String host = "192.168.1.2";
        try {
            client.connect(5000, host, Network.port, 8889);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

I just don’t know how to handle moments like ‘connecting’ etc on a main thread - in the menu activity. I need to create a progressdialog, block it and update, when clients gets connected or reconnected again.

If there is anyone that could help, I would be grateful :slight_smile: