Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.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:AsyncTask如何使用等待/通知_Android_Multithreading_Android Asynctask - Fatal编程技术网

Android:AsyncTask如何使用等待/通知

Android:AsyncTask如何使用等待/通知,android,multithreading,android-asynctask,Android,Multithreading,Android Asynctask,是否可以在异步任务中调用wait¬ify?到目前为止,我试图使用它们,但它所做的一切都会永远阻止异步任务。我怎样才能克服这个问题?我的用法是:我有一个相机帧生成,我想把它发送到服务器不断然而,我想做一些更好的比 while( true){ if (frameAvaialble){ send(frame) } } 这会消耗无用的CPU电源。您可以尝试条件变量 您可以尝试ConditionVariable 听起来像是:你的AsyncTask是消费者,而其他生成帧的源是生产者。研

是否可以在异步任务中调用wait¬ify?到目前为止,我试图使用它们,但它所做的一切都会永远阻止异步任务。我怎样才能克服这个问题?我的用法是:我有一个相机帧生成,我想把它发送到服务器不断然而,我想做一些更好的比

while( true){
 if (frameAvaialble){
    send(frame)
  }
}

这会消耗无用的CPU电源。

您可以尝试
条件变量


您可以尝试
ConditionVariable


听起来像是:你的AsyncTask是消费者,而其他生成帧的源是生产者。研究使用同步队列?有两种方法可以干净地处理此问题。最好的方法是使用侦听器检测帧是否准备就绪。作为替代,我建议您使用计时器并定期检查。听起来像是:您的AsyncTask是消费者,而生成帧的其他源是生产者。研究使用同步队列?有两种方法可以干净地处理此问题。最好的方法是使用侦听器检测帧是否准备就绪。作为替代,我建议您使用计时器并定期检查。
private ConditionVariable mCondition = new ConditionVariable(false);


while( true ){
   mCondition.block();
   send(frame)
}

//other code
frameAvaialble = true;
mCondition.open();