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 <[email protected]> wrote:
> On Fri, Apr 15, 2011 at 6:43 PM, Diego Tori
>
> <[email protected]> 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 chance you can show me how to modify the above code to
> > utilize AlarmManager to have it sleep before the onReceive gets called
> > again?
>
> My interpretation of what you're trying to accomplish is that you have
> 1+ activities that need to hear about scan results, for a startScan()
> kicked off every so often.
>
> Let's assume a service being bound to by the activities is the right
> answer. I'm more than a tad skeptical on that, actually, but I'm
> trying to keep this simple relative to your apparent current
> implementation.
>
> Step #1: In onCreate() of the service, you register a
> BroadcastReceiver for SCAN_RESULTS_AVAILABLE_ACTION, then call
> startScan(). onCreate() then returns. Or, if this should not be going
> for the entire time the service is in memory, expose a method from
> your Binder that does the aforementioned work and returns.
>
> Step #2: When SCAN_RESULTS_AVAILABLE_ACTION occurs and your
> BroadcastReceiver is called with onReceive(), you:
>
> Step #2a: Arrange for your next scan (e.g., use Timer/TimerTask to
> call startScan() after some delay -- I agree that AlarmManager is not
> ideal for this particular implementation)
>
> Step #2b: Call getScanResults() and asynchronously notify the
> activities (your own broadcast Intent that the activities register
> for, or via a callback method the activities register with the
> service, or via a Messenger, or via a PendingIntent created by
> createPendingResult(), etc.).
>
> Step #3: In onDestroy(), you unregister your BroadcastReceiver and
> arrange to not invoke the next scan (e.g., cancel the Timer).
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 3.0 Programming Books:http://commonsware.com/books

-- 
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