Reputation: 3571
My main objective is to write a method in Java that could initiate a WiFi scan, wait for the scan results and return them.
I know that I have to register a BroadcastReceiver
and wait for Android to broadcast an Intent
with the scan results. My question is - is it possible to block the thread from the moment I called startScan()
until the receiver's onReceive()
method is triggered? I tried using a wait()/notify() pair and using a CountDownLatch
- both blocked the thread, however onReceive was never called.
EDIT: The whole procedure takes place in a worker thread, I'm not blocking the UI thread.
How can this be done?
Upvotes: 1
Views: 135
Reputation: 18725
You shouldn't block the UI thread - ever. When you do, your device will stop responding, and this is terrible UI.
You can block other operations within your app (but disabling buttons, etc) - but you should never, never block the UI thread (and the OS makes it hard to do so).
Upvotes: 1