Office Hours — Today, February 8

Thursday, February 3

Feb 8
7:55 PM
Mark M.
has entered the room
7:55 PM
Mark M.
turned on guest access
8:05 PM
Julius
has entered the room
Mark M.
howdy, Julius!
Julius
hi Mark
Mark M.
how can I help you today?
Julius
(well I will be seeing you hopefully - lucky up got up at 545am yesterday and captured the URL as I started getting 503w)
8:10 PM
Mark M.
yeah, that was quite the fiasco
Julius
I have a concurrent write database issue
I have a long running task which downloads information from a service provider in batches and then populates a local database
this takes quite some time as there's a fair amount of information.
at the same time a user can download a file and some state gets written to the database
if I get two writes I get a database is locked error
Mark M.
correct
Julius
I can catch this, but unfortunately the state in the views is no longer good for the user
I was just wondering if you had any advice... (I hope that made some sense)
Mark M.
don't do concurrent writes
Julius
heheh
:)
Mark M.
either make your "long running task" an IntentService and have the "some state gets written to the database" be handled by it
Julius
is there any way I can queue up database transactions?
Mark M.
or use Java synchronization mechanisms
the IntentService gives you a queue
or use a LinkedBlockingQueue from java.util.concurrent, along with your own thread to monitor it
Julius
ah it is an IntentService so maybe I need to merge these operations (sounds like what you're saying)
Mark M.
it's one solution
Julius
that sounds very smart - actually goes back to something you mentioned to me once before
8:15 PM
Julius
btw - when you say the IntentService gives a queue, is that because it's all in one thread?
Mark M.
plus, there's a queu
er, queue
every onStartCommand() pops the Intent onto the queue
the background thread kicks off
grabs first Intent off the queue, and calls onHandleIntent()
when done with that Intent, sees if anything else is on the queue
if yes, lather, rinse, repeat
if no, stopSelf() and shut down the thread
It's using the queue mechanism inside of a Looper
Julius
ah ok... wow thanks for that - I had no idea.
Mark M.
it's actually a fairly short class
Julius
hmmm so the downside for the user is that if the sync process is happening the download will have to wait
Mark M.
the download doesn't have to wait
updating the database has to wait
it's up to you whether those two operations are tightly coupled or not
Julius
oh I see so maybe I handle the database operations separately...?
That could work
it's only temporary
Mark M.
I meant do the download separately from the database operations
if that's possible for your app
8:20 PM
Julius
oh yes
what I meant but expressed correctly.
no
not expressed
ok thank you very much
well I'd booked tickets and hotel so thank goodness I managed to save the state of my registration in a URL which I later put into a browser 3 hours later - so I hope to see you so you can put a face to the name
and I can thank you in person!
oh I have one other questions
question
Mark M.
bear in mind that there's a zillion people attending I|O
Julius
(yeah I'll be brief :))
Mark M.
it's actually a bit tough to run into somebody
Julius
well I'll do my best
being in NZ it's unlikely I'll get to meet people again.
so
I have had a few projects come up where people mention using tools like PhoneGap
this build for multiple platforms - iPhone, BB, android etc
Mark M.
yup
Julius
build => builds
have you any experience with this - know any pros / cons?
for my own part it could create some competition but I'd like to know whether I should be learning these tools
(as if Java and Android isn't enough)
8:25 PM
Mark M.
PhoneGap is covered partially in _Android Beyond Java_, and that chapter is moving to _The Busy Coder's Guide to Android Development_ in the next release
I have not used it anywhere but Android, though
Julius
oh oops I didn't see that
I'll go take a look
thank you
Mark M.
of all the alternative application frameworks, it's my favorite
however, it assumes you're decent with HTML/CSS/JS
Julius
yeah not exactly my area
Mark M.
particularly AJAX-style, the whole-app-is-a-page sort of app
Julius
there was one I tried using something called lua but the apk was massive fro memory
thanks for your time.
Mark M.
that too is covered in _Android Beyond Java_, in the NDK chapters, that will eventually move to _Tuning Android Applications_
Lua is not designed for full Android apps
more of a scripting language, kinda like how it is used in WoW and such
8:30 PM
Julius
hi again - just noticed that there's a <<TBD>> under the Using PhoneGap section and the following headings are empty. (just downloaded from your site).
Not a problem for me
I'm just getting a feeling for it so that was brilliant to read.
Mark M.
that book is a work in progress
or was, anyway]
Julius
ah right no worries
:)
Mark M.
that chapter will be completed for the next edition of _The Busy Coder's Guide to Android Development_
Julius
ok I'll leave you in peace - thank you very much for the help - that database issue was starting to creep into my sleep!
bfn
Mark M.
see ya!
Julius
has left the room

Thursday, February 3

 

Office Hours

People in this transcript

  • Julius
  • Mark Murphy