Basically.  You'll want to manage messages -- you don't want to stack up
multiple DO_WIFI_SCAN messages.  If you want to do something every X ms, in
your message handling you would post a new message each time with a delay of
X.  Use Handler.removeMessages() to ensure that you don't have multiple
timing messages active.

This approach is just a basic message loop, so just follow the same approach
you'd use on other platforms for message-based code.

HandlerThread is just a Thread running its own message loop, so instead of
using sleep() to do timing you can do the same delayed message posting.

On Mon, Apr 18, 2011 at 4:53 PM, Diego Tori
<[email protected]>wrote:

> I don't think it's doing any blocking operations at all since startScan
> calls back onReceive rather quickly (even on a G1), and then I just use the
> returned SSID data to call back to the activities bound to the service based
> on the existence of a pre-determined SSID that I'm trying to find in that
> list.
>
> So in essence, you want me to do the following:
>
> Create Handler object and then within my BroadcastReceiver's onReceive
> method, do the following:
>
> final int DO_WIFI_SCAN = 0;
> private Handler _handler = new Handler(){
>     @Override
>     public void handleMessage(Message msg){
>            switch(msg.what){
>                  case DO_WIFI_SCAN:
>                      //call startScan here
>                      break;
>            }
>     }
> };
> public void onReceive(){
>      //Iterate through the SSID's
>      _handler.sendEmptyMessageDelayed(DO_WIFI_SCAN, SLEEP_TIME);
> }
>
>
> Also, how would I model it if I try to use the HandlerThread approach? In
> other words, where would I call startScan when starting thread, in run or in
> the HandlerThread's constructor?
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to