Office Hours — Today, June 23

Tuesday, June 21

Jun 23
7:20 PM
Mark M.
has entered the room
7:25 PM
Mark M.
turned on guest access
Scott P.
has entered the room
Mark M.
howdy, Scott!
Scott P.
Hello Mark
Haven't quite got rid of me yet
questions about threading for you today
Mark M.
fire away
Scott P.
Alright, so I need to send something to a server
so obviously I want to do that in an async task
7:30 PM
Mark M.
or an IntentService, but certainly in a non-main-application thread
Scott P.
I'm currently doing this inside of a service
I'm using one of Googles new methods for connecting with app engine
and it doesn't seem to support concurrency
and I end up needing to send multiple things
so while one is still sending, I end up with another that needs to be sent
how would you recommend I do this?
I was thinking I would probably use a blocking queue
but I'm really not that familiar with concurrency
Mark M.
two questions:
1. what is making the decision that something needs to be sent? an activity? a service?
2. what happens to your service when there is nothing more to be sent?
Scott P.
1. the Service
2. It stays open. OnStartCommand returns Service.START_STICKY;
Mark M.
then I'd dump the AsyncTask (you're presumably not using onPostExecute() anyway) and use a thread with a LinkedBlockingQueue
Scott P.
ok
7:35 PM
Scott P.
how do I implement a thread? I tried for something simple once, but it kinda failed, so I dumped it and went back to AsyncTask
Mark M.
you'll see an example of this in the AdvServices/RemoteServiceEx project
Scott P.
ok
Mark M.
I use a thread and LinkedBlockingQueue to asynchronously handle requests from a client over a remote service binding
this is covered in the Advanced Services chapter of _The Busy Coder's Guide to Advanced Android Development)
Scott P.
ok
let me load up that project real fast
Mark M.
to actually run it, you'd also need AdvServices/RemoteClientEx
since it's a remote service sample
Scott P.
hey
what is the difference between the Google API's and the Android X.X for the build targets
7:40 PM
Mark M.
Google APIs have Google Maps
Scott P.
is that the only difference?
Mark M.
AFAIK, yes
Scott P.
so unless I want to use google maps I should just use the sdk
?
Mark M.
not necessarily
for an AVD, I'd use the Maps one, because devices will have Maps
(at least in general)
for a build target, stick with the plain SDK unless you're using Maps, though
Scott P.
AVD?
Mark M.
emulator image
7:50 PM
Scott P.
hmmm
so it looks like the thread is paused here
Job j=q.take();
Mark M.
correct
take() is a blocking call
Scott P.
and that's ok?
it's ok to just have a paused thread... all the time?
Mark M.
that's kinda the point
if there is nothing to do, you want the thread to consume no CPU time
so, you block
now, you wouldn't call take() on the main application thread, because that thread has work to do
Scott P.
i just thought it was a waste to have a thread taken and paused the entire time
I wasn't sure what that would do
but that won't have a negetive performance impact at all on the phone?
*negative
Mark M.
no
most threads in most OSes are paused
that's the normal state of affairs for a thread
they only run when there's something to do
Scott P.
is there a limit to the number of threads an application can have?
7:55 PM
Mark M.
well, I wouldn't have dozens
Scott P.
I'm sorry, I meant phone
Mark M.
an Android app uses six or so just out of the box, all but the main application thread are usually paused
the phone doesn't have threads
processes have threads
Scott P.
right
Mark M.
the issue isn't having threads, it's *having threads doing work*
Scott P.
but the processor has to handle those threads
Mark M.
blocked threads are doing no work
they consume no CPU time
Scott P.
ok
cool beans
that's really exciting
Mark M.
you might consider picking up _Concurrent Programming in Java_ if Java threading is new to you
Scott P.
430 pages >.<
Mark M.
yeah, well, don't read it all in one sitting... :-)
Scott P.
thats the problem
when I get a good book I can't put it down
I went through half of your first book in 2 days
Mark M.
wow
Scott P.
and then I had to stop for like a week and a half to catch back up in school
out of curiosity, how many subscriptions have you sold?
you don't have to answer that
Mark M.
lots
8:00 PM
Scott P.
lol
8:00 PM
Scott P.
nice and vague
Mark M.
let's put it this way...
I offer the Four-to-Free Guarantee, which says that book editions go Creative Commons after four years or 4,000 copies sold
where "copies" combines print + Warescriptions
I have plenty of editions in Creative Commons licensed mode now (you'll see them on the Four-to-Free Guarantee tab on each book page on the main site)
Scott P.
I seee
alright
well
I'll ask you 1 more oppinion question
and then I'll leave you to it
I accidentally ran into 2 internships, both of which deal with mobile development with android. I've submitted my resume, and one of them is pretty darn interested in me
8:05 PM
Mark M.
cool!
Scott P.
I'm assuming that they are going to ask me for a pay range during the interview
how much would you recommend I request?
Mark M.
beats me
that'd be driven more by what interns get nowadays, than by Android
Scott P.
pfft
yeah I suppose you are right
Mark M.
it was at least when I was intern age
Scott P.
how old are you now?
Mark M.
too old to be answering that question
Scott P.
yeah I figured
Mark M.
let's just say "twice your age" is probably in the ballpark
Scott P.
it just sounded by the question above that you were interning when android was around
Mark M.
oh, no
Scott P.
which kinda shocked me as that'd put you around my age
Mark M.
when I was an intern, a portable computer weighed about 15 pounds
Scott P.
anyways Mark. I'll see you later, I'm sure. I see these office hours as too valuable of a resource not to try and take advantage of them :-P
Mark M.
hey, that's why they're here
happy to help
Scott P.
haha, well I appreciate it
8:20 PM
Scott P.
has left the room
9:00 PM
Mark M.
turned off guest access

Tuesday, June 21

 

Office Hours

People in this transcript

  • Mark Murphy
  • Scott Pierce