Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android用户界面在使用CountDownLatch时被冻结_Android_Asynchronous_Async Await_Countdownlatch - Fatal编程技术网

Android用户界面在使用CountDownLatch时被冻结

Android用户界面在使用CountDownLatch时被冻结,android,asynchronous,async-await,countdownlatch,Android,Asynchronous,Async Await,Countdownlatch,我有一个应用程序,可以将数据包发送到远程设备,获取响应并处理它们。 我想使用倒计时闩锁,在处理传入消息之前设置它,当我完成后,我倒计时闩锁并释放它 我想这样做,因为我认为这将允许我在消息处理过程中同时向用户显示进度条动画 但是,当我启动闩锁时,动画被冻结 有没有一种方法我可以做到这一点,仍然显示动画的进展给用户 这是我的代码: 获取ip作为字符串并发送connect消息的片段: device.getController().connect(ip); if (device.getC

我有一个应用程序,可以将数据包发送到远程设备,获取响应并处理它们。 我想使用倒计时闩锁,在处理传入消息之前设置它,当我完成后,我倒计时闩锁并释放它

我想这样做,因为我认为这将允许我在消息处理过程中同时向用户显示进度条动画

但是,当我启动闩锁时,动画被冻结

有没有一种方法我可以做到这一点,仍然显示动画的进展给用户

这是我的代码: 获取
ip
作为字符串并发送
connect
消息的片段:

    device.getController().connect(ip);
    if (device.getController().isConnected()) {
        device.getController().navigate(R.id.navigation_remote);
    }
这是
device.getController().isConnected()
方法,它使用锁存并等待连接:

public boolean isConnected() {
    try {
        if (!connecting) {
            return false;
        }
        client.getNanoClientOpenedLatch().await(); // wait until nano client is open todo add timeout
        if (client.getNanoClient() != null) {
            client.getNanoClient().getChannelsCountDownLatch().await(); // wait until all channels are open
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return true;
}