Sorry to bump the thread, but after creating a HandlerThread, all of the
locking stopped and the service stopped on a dime after unbinding even when
it waited for the allotted time before the next scan. Anyways, I was
wondering if I managed to implement it correctly:
class MyHandlerThread
static int TICK_MSG = 1;
static long TICK_TIME = 1000; / 1 second
class MyHandler extends Handler {
public void handleMessage(Message msg) {
switch (msg.what) {
case TICK_MSG:
sendMessageDelayed(obtainMessage(TICK_MSG), TICK_TIME);
You are re-implementing a lot of things that HandlerThread already does for
you. For example, the run() method is already implemented to drive the
message loop; you shouldn't replace that impl. If you want to do setup, you
do that in HandlerThread.onLooperPrepared().
Likewise, the getHandler()
Dianne-
I expect your suggestion is sound, since you do know Android so well,
and in particular, what Handlers are good for and how to use them. I
also expect that the reason Diego did not use a Handler was that he
could easily find copious documentation on how to use a raw thread,
but nothing
So yeah, I managed to try calling the wifi scanner in this fashion within my
thread:
private Object _lock = new Object();
private final long SLEEP_TIME = 15000; //Scan every 15 secs
private final long WIFI_SCAN_TIMEOUT = 6; //One minute timeout
for getting called
I suggest not using a raw thread. If you need it on a separate thread, use
a HandlerThread and Handler.sendMessageDelayed() to do your timing.
Even better -- if the code is not doing blocking operations, there is no
need for another thread at all; just make a class with a Handler in it and
use
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
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
That's the thing, it has to be short intervals in between scans since
this has almost real-time implications, no greater than 15 secs at
most, so I dunno how AlarmManager would fit into the equation. Is
there any chance you can show me how to modify the above code to
utilize AlarmManager to have
On Fri, Apr 15, 2011 at 6:43 PM, Diego Tori
diegotoridoesandr...@gmail.com wrote:
That's the thing, it has to be short intervals in between scans since
this has almost real-time implications, no greater than 15 secs at
most, so I dunno how AlarmManager would fit into the equation. Is
there any
You pretty much hit the nail on the head. I just need to figure out
the best way to add the time buffer in between the startScan calls
without creating too much overhead and accomplishing the task at hand.
On Apr 15, 6:59 pm, Mark Murphy mmur...@commonsware.com wrote:
On Fri, Apr 15, 2011 at
11 matches
Mail list logo