Office Hours — Today, December 16

Thursday, December 12

Dec 16
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:40 PM
Sean D.
has entered the room
Mark M.
hello, Sean!
how can I help you today?
Sean D.
hi
i had a quick question about using LocationClient
i have multiple activities that need to get a location so i was wondering if there was a good way to globally access the location and reuse it across my app?
7:45 PM
Sean D.
currently i have each Activity connecting and using its own LocationClient instance
Mark M.
use an event bus (LocalBroadcastManager, Otto, greenrobot's EventBus)
send an event when you get an updated fix, to distribute it to anyone that is around that needs it
Sean D.
okay so i would have a separate class that implements the LocationClient callbacks which sends the broadcast? and it's always connected?
Mark M.
yes
Sean D.
actually being connected doesn't drain the battery, right?
Mark M.
might be a bound service, so that once all activities unbind, it shuts down
Sean D.
ah okay, i didn't realize a bound service could bind to more than one Activity... that's a good idea
Mark M.
regarding battery, I can't answer that, as Play Services is closed source
and I have no idea if active clients changes its behavior
it *probably* does
Sean D.
oh
i was thinking battery drain would just come from requesting frequent location updates (which i don't need)
my updates would be requested every 5 mins or so
7:50 PM
Mark M.
again, I have no idea what Play Services does with a five-minute timeout
one would hope it leverages that timeout to consume less power
Sean D.
yeah i guess i'll just have to do some testing
if it happens that it does drain the battery, i'm assuming the correct way to go would be to use a timer and reconnect every 5 mins or so?
Mark M.
I'd use a ScheduledExecutorService, but, yes, that's an option
Sean D.
ah okay, thanks... i haven't used timers or anything before so i wasn't sure about that
what would be the advantage of using a bound service as opposed to just a regular class that gets created in the main activity? the automatic cleanup?
Mark M.
first, I think you need a Context, and that can't be any of the Activity instances to avoid leaks
which leaves you with Application or a Service
Sean D.
ah
Mark M.
you could do your own reference-counted other class too
the problem with these chats is that I get questions from left field and have to try to answer on the fly :-)
Sean D.
haha, yeah
7:55 PM
Sean D.
well thanks a lot for the advice
Mark M.
you are very welcome
Sean D.
see you later, probably in another several weeks... haha
Mark M.
OK, sounds good
8:10 PM
Sean D.
has left the room
8:30 PM
Mark M.
turned off guest access

Thursday, December 12

 

Office Hours

People in this transcript

  • Mark Murphy
  • Sean Durkin