[android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-27 Thread Diego Tori
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

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-27 Thread Dianne Hackborn
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);

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-27 Thread Dianne Hackborn
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()

[android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-20 Thread Indicator Veritatis
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

[android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-18 Thread Diego Tori
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

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-18 Thread Dianne Hackborn
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

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-18 Thread Diego Tori
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

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-18 Thread Dianne Hackborn
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

[android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-15 Thread Diego Tori
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

Re: [android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-15 Thread Mark Murphy
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

[android-developers] Re: Calling a system service in fixed intervals within another service

2011-04-15 Thread Diego Tori
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