Android Emitter.Listener not working

前端 未结 1 593
我寻月下人不归
我寻月下人不归 2021-01-25 18:57

I\'m making an app with socket IO, it connects correctly to the server, but it doesn\'t listen to events.

Here\'s part of my code:

private Socket mSocket         


        
1条回答
  •  失恋的感觉
    2021-01-25 19:12

    try to show toast on UI thread instead of different thread using getActivity().runOnUiThread

    private Emitter.Listener onSendFile = new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            String data = (String) args[0];
    
            mSocket.emit("fileok", "OKIDOKI");
    
    getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), data, Toast.LENGTH_LONG).show();
                    }
                });
        }
    };
    

    0 讨论(0)
提交回复
热议问题