[Android Software Development] martintzvetomirov:
I'm in a strange position. Here's my Looper class

[color=RED][b]class[/b][/color] LooperThread [color=RED][b]extends[/b][/color] Thread [color=BLUE][size=+1][b]{[/b][/color][/size]

[color=RED][b]private[/b][/color] [color=RED][b]int[/b][/color] messid [color=BLUE][size=+1]=[/color][/size] [color=BROWN]0[/color][color=BLUE][size=+1][b];[/b][/color][/size]

[color=RED][b]private[/b][/color] [color=RED][b]boolean[/b][/color] notSatisfied[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
[color=GREEN][i]//some unimportant code goes here
[/i][/color] [color=BLUE][size=+1][b]}[/b][/color][/size]

[color=RED][b]private[/b][/color] String getErrMsg[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
[color=GREEN][i]//more unimportant code
[/i][/color]	[color=BLUE][size=+1][b]}[/b][/color][/size]

[color=RED][b]public[/b][/color] [color=RED][b]void[/b][/color] run[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
Looper[color=BLUE][size=+1][b].[/b][/color][/size]prepare[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]

mChildHandler [color=BLUE][size=+1]=[/color][/size] [color=RED][b]new[/b][/color] Handler[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
@Override
[color=RED][b]public[/b][/color] [color=RED][b]void[/b][/color] handleMessage[color=BLUE][size=+1][b]([/b][/color][/size]Message msg[color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]

[color=RED][b]int[/b][/color] max [color=BLUE][size=+1]=[/color][/size] msg[color=BLUE][size=+1][b].[/b][/color][/size]arg1 [color=BLUE][size=+1]*[/color][/size] [color=BROWN]1000[/color][color=BLUE][size=+1][b];[/b][/color][/size]
messid [color=BLUE][size=+1]=[/color][/size] msg[color=BLUE][size=+1][b].[/b][/color][/size]what[color=BLUE][size=+1][b];[/b][/color][/size]

[color=RED][b]try[/b][/color] [color=BLUE][size=+1][b]{[/b][/color][/size]
[color=RED][b]int[/b][/color] count [color=BLUE][size=+1]=[/color][/size] [color=BROWN]0[/color][color=BLUE][size=+1][b];[/b][/color][/size]
[color=RED][b]while[/b][/color] [color=BLUE][size=+1][b]([/b][/color][/size]notSatisfied[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][color=BLUE][size=+1]&[/color][/size][color=BLUE][size=+1]&[/color][/size][/color][/size] [color=BLUE][size=+1][b]([/b][/color][/size]count [color=BLUE][size=+1]<[/color][/size] max[color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
count[color=BLUE][size=+1]+[/color][/size][color=BLUE][size=+1]=[/color][/size]waitduration[color=BLUE][size=+1][b];[/b][/color][/size]
wait[color=BLUE][size=+1][b]([/b][/color][/size]waitduration[color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]
[color=BLUE][size=+1][b]}[/b][/color][/size]

[color=BLUE][size=+1][b]}[/b][/color][/size] [color=RED][b]catch[/b][/color] [color=BLUE][size=+1][b]([/b][/color][/size]Exception e[color=BLUE][size=+1][b])[/b][/color][/size] [color=BLUE][size=+1][b]{[/b][/color][/size]
[color=GREEN][i]// TODO: handle exception
[/i][/color]	[color=BLUE][size=+1][b]}[/b][/color][/size]
[color=RED][b]if[/b][/color] [color=BLUE][size=+1][b]([/b][/color][/size]notSatisfied[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size] throwError[color=BLUE][size=+1][b]([/b][/color][/size]getErrMsg[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]

[color=RED][b]super[/b][/color][color=BLUE][size=+1][b].[/b][/color][/size]handleMessage[color=BLUE][size=+1][b]([/b][/color][/size]msg[color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]
[color=BLUE][size=+1][b]}[/b][/color][/size]
[color=BLUE][size=+1][b]}[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]

Looper[color=BLUE][size=+1][b].[/b][/color][/size]loop[color=BLUE][size=+1][b]([/b][/color][/size][color=BLUE][size=+1][b])[/b][/color][/size][color=BLUE][size=+1][b];[/b][/color][/size]

[color=BLUE][size=+1][b]}[/b][/color][/size]
[color=BLUE][size=+1][b]}[/b][/color][/size]

I want to call a method of a system service which when ready invokes a handle in my code. The problem is that I wanted to make several inquiries to that service one after another but if a previous inquiry has not finished (i.e. invoked a method) then the service just ignores it. So I decided to device a pipeline using Handlers and Loopers. The thing I'm doing in my main class is to post a runnable (with a command to the service) to the handler and then post a message. The message contains the length of the maximum allowed waiting time (if the execution of the runnable exceeds it then it returns an error). The problem is that the wait() statement does nothing. It does not make the Looper wait until notSatisfied() returns false.

Can you propose how to make the Looper wait?

In case you are wondering what the messages consist of. msg.arg1 is the maximum allowed wait time in seconds, msg.what is an index of the service method which I device and it is handled by notSatisfied() and getErrMsg().