Android: AsyncTask how to use wait/notify

Is it possible to call wait & notify inside an AsyncTask? So far, I tried to use them but all it does to block the AsyncTask forever. How can I overcome this? My usage is: I have a camera frame generated, and I want to send it to server continously however, I want to make something better than

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

Which drains useless CPU power.

Answers


You can try ConditionVariable, http://developer.android.com/reference/android/os/ConditionVariable.html

private ConditionVariable mCondition = new ConditionVariable(false);


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

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

Need Your Help

calling C main from Objectivec

objective-c c parameters parameter-passing main

I want to call a C classes main function from within another class (which is written with objectiveC). I would like to pass some arguments to the main. I tried it like this, but the frist parameter...

Sorting of Gridview data

c# gridview

I have A Grid view and I want to sort the Gridview .I tried severel methods from google and they are not working in my side.

Parsing strings with regex into different patterns

regex

Could someone show me a correct syntax. The complete string should consist of only numbers and characters and whitespaces in each pattern except in type. The type and one parm are mandatory. The

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.