Office Hours — Today, February 15

Thursday, February 10

Feb 15
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Kevin M.
has entered the room
Mark M.
howdy, Kevin!
scott k.
has entered the room
Kevin M.
Hi There
scott k.
hi everyone
4:00 PM
Mark M.
howdy, Scott!
Kevin, you got in first...do you have a question?
Kevin M.
Just going to listen for now
Mark M.
OK
Scott, do you have a question?
NetApex
has entered the room
scott k.
struggling with screen lock, but i think i just figured it out
Mark M.
howdy, NetApex!
scott k.
i really planned to just listen - let you know i enjoy your books
Mark M.
thanks!
NetApex
Hello there
Mark M.
NetApex, do you have a question?
NetApex
I don't at the moment.. because I forgot what it was. Give me a couple it will come back.
Mark M.
Um, OK
if anyone has a question, chime in
Kevin M.
So how come we don't have the honeycomb sdk yet?
Mark M.
well, we have the preview SDK
Kevin M.
It's not that complete though is it?
Mark M.
it's a mixed bag
in terms of new stuff, it is over-complete -- I suspect they are still deciding what is baked enough that they're leaving in
however, the preview SDK appears to be missing Google Maps and such
but the ways of Google are mysterious
Kevin M.
Strange that 3.0 is coming and not many people have 2.3
Mark M.
oh, that's not surprising
4:05 PM
Kevin M.
Since no one has a question, I'll ask one
I'm still having problems with Activities and the singleTop, singleTask settings
I did a test with 3 activities and switched back and forth. Seems like a lot of activities can get created
David
has entered the room
Kevin M.
It would be nice to have an activity stay around a bit longer
Mark M.
that's not necessarily a problem
why?
(btw, howdy, David!)
David
Hi
Kevin M.
I'm working on a project that someone else wrote that has a lot of initialization stuff in the main activity and they expect it to stay around
A lot of global static variables
Mark M.
if they're caches, that's not a big deal
Kevin M.
So if that activity get's recycled then the variable will always be there?
Mark M.
so long as the process is around, yes
static data members are static
they live outside any given instance of any class
semantically, they're globals
now, if the process goes away (e.g., user presses HOME and hours elapse), the statics go away as well
which is why they're fine for caches
but they are no substitute for a persistent data model
4:10 PM
Kevin M.
Should an activity be just a light-weight container for a view?
I'm thinking about putting code into an application object
Mark M.
from an MVC standpoint, the activity is more or less the controller
NetApex
(boom, thanks Kevin! That reminded me of my question!)
Mark M.
Application objects are more or less equivalent to static data members, in terms of lifetime
Kevin M.
Go ahead NetApex
Mark M.
a bit more awkward to access, but you get the benefit that they're a Context
NetApex
I have an app that I was working on that did a swipe to get to the next/previous activity. Would it be less process intensive to make the swipe go to another view instead?
Mike
has entered the room
Mark M.
that's not possible to answer in the abstract
NetApex
Consider the activity just has text and an image
Mark M.
tactically, yes, it will be less CPU intensive to flip to another view (e.g., my ViewSwiper component)
strategically, there may be reasons for having them as separate activities
I just blogged a bit in this area: http://commonsware.com/blog/2011/02/14/nat…
NetApex
Ahh nice timing
Ok going to go have a read really fast
Mark M.
meanwhile...
Kevin, do you have a question?
Kevin M.
So many questions....
Mark M.
oh, wai, sorry
mixed names up
trying to get the newcomers
David, do you have a question?
David
I have a question on PushEndpointDemo. I found out that onMessage()in C2DMBaseReceiver.java doesn't call onMessage() in C2DMReceiver.java
4:15 PM
Mark M.
C2DMReceiver is a subclass of C2DMBaseReceiver
David
Yes.
Mark M.
onHandleIntent() of C2DMBaseReceiver dispatches to the various abstract methods, such as onMessage()
there is no onMessage() of C2DMBaseReceiver, except as an abstract method declaration
hence, onMessage() in C2DMBaseReceiver is not supposed to call onMessage() in C2DMReceiver
David
How can I make onMessage() in C2DMReceiver.java is called?
Mark M.
follow the overall C2DM recipe
Chapter 20 of _The Busy Coder's Guide to Advanced Android Development_ IIRC
David
Thanks
Mark M.
Mike, do you have a question?
OK, Kevin, back to you, for real this time :-)
Mike
I have a service component lifecycle question. What happens to a service which does not respond to ondestroy (if called) when the component is in its own process? I'm finding little information on the full dirty lifecycle :-)
4:20 PM
Mark M.
there is no such concept as "does not respond to onDestroy()"
if you do not override it, the implementation in Service gets called
if it takes too long, Android nukes the component anyway
Kevin M.
In regards to Services, what's the best way to implement a service that you want to stick around after an activity finishes but that you can still interact with?
Mark M.
you have to use startService()
either use the command pattern (i.e., send data via startService())
or use both startService() *and* the binding pattern
the latter is a bit unusual
fitz
has entered the room
Kevin M.
Problem with startService is that the service doesn't end unless you end it, right? Then how do you know when your app is done?
Mike
has left the room
Mike
has entered the room
Kevin M.
to stop the service
Mark M.
you don't
do not start services without a clear picture of concretely when you will end them
hence, this goes back to your "you want to stick around after an activity finishes"
Kevin M.
We have a service (old code) that waits on an object (suspending itself) and so it lasts forever
Mike
My machine into hibernate mode. I didn't see your response. :-)
Mark M.
Kevin: you really need to rewrite that
Kevin M.
I'm in the process of doing that. That's why I need to know the best way to do it
4:25 PM
Mark M.
(Mike: scroll up in the chat log -- the messages should be there, no?)
Kevin: it is impossible to advise you in the abstract
Mike
it went to sleep before your response
Mark M.
either the service needs to know when to shut down based on work (e.g., a downloader IntentService)
Kevin M.
We have a downloading/uploading service
Mark M.
OK
Kevin M.
It waits in a thread for more files
Mark M.
ick
you're better served having something tell it "here's what to upload/download" via startService()
Kevin M.
If it didn't, it would shut down. I guess we could have a combination of IntentService and binding?
Mark M.
then, it can shut down safely when there are no more outstanding requests
no, you can't use that combination
just pass the upload/download details in extras on the startService() Intent
Kevin M.
IntentServices will start and end when finished, which is good
Mark M.
and it already has a background thread, which simplifies matters
but it only works well when told what to do via startService() vs. some sort of internal monitoring (e.g., thread watching for changes in a directory)
Kevin M.
One of the problems is we need to communication progress so the service sends info back
Mark M.
broadcast an Intent, or use a Messenger
Kevin M.
Ah
Someone else can go
Mike
In the isolated process / service not responding case to ondestroy - does the framework just spin up another service component?
Mark M.
No
it just terminates the component
David
has left the room
David
has entered the room
4:30 PM
Mark M.
if it was already being destroyed, it will not create a new one
Mike
ok. What happens? process gets yanked?
Mark M.
the component is terminated
if there are no running components in the process, eventually the process will be killed
Mike
ok. if you have threads lingering when that happens?
Mark M.
first, don't have threads lingering
and all threads go away when the process hosting those threads is killed
Mike
ok. how would you build something using JNI that monitors file change notifications then that can shut down?
Mark M.
well, I wouldn't, because I don't use JNI, outside of book examples
it's been 11 years since I did any serious C/C++ work
regardless, it should not be in its own process, anyway
Mike
ok. Am I kind of stepping outside the design paradigm to want a long running service that can interface with the lower level system in this way?
Mark M.
long-running services themselves are "outside the design paradigm"
except in rather unusual circumstances (e.g., VOIP client)
JNI doesn't really influence that one way or another
4:35 PM
Mark M.
checking periodically, ideally with a configurable period, is more in line with Android development models
fitz: do you have a question?
Mike
ok. Is there something else you'd recommend on android to build a long running service or really, i'm just in for trouble
fitz
not - reading discussion and on conference (yawn) call
Mark M.
Mike: that's impossible to answer in the abstract
avoiding long-running services is very important
Mike
well, my example is i want to build a file monitor that starts with the phone, but i don't want it to run when the phone is powered off
Mark M.
by definition, it can't run when the phone is powered off
off is off
Mike
well, yes
i mean, i wouldn't take a wake lock, etc
Mark M.
your problem is "build a file monitor"
Mike
correct
Mark M.
why do you want to "build a file monitor"?
Mike
I have an application on the market that sends photos once they are dropped from the camera application
Mark M.
then poll
AlarmManager, wake up every so often, look for images
let the user choose the polling period via a PreferenceActivity
Mike
ok. so you'd drop the monitor and do a periodic poll instead?
Mark M.
absolutely
Mike
sure. That's easy enough
Mark M.
gives the user more control, keeps the service out of RAM except when it is actually delivering value
4:40 PM
David
has left the room
Mark M.
if you don't use a _WAKEUP alarm, it won't occur when the device is asleep
Mike
ok. That helps a lot Mark. The reliability was pushing me this way already :-)
Mark M.
OK
anyone else have a question?
Brian C.
has entered the room
Kevin M.
What are the pluses/minues to using a Messenger vs Broadcasting?
NetApex
No, but thanks for that blog post!
Mark M.
NetApex: you're welcome!
Kevin: broadcasting is nice -- works across multiple activities, you can use an ordered broadcast to put up a Notification if no activities are visible, etc.
however, for Android 1.5, it is always a true broadcast, to the whole device
API level 4 introduced setPackage(), which lets you control the scope to keep it within your app
Kevin M.
We're going to only be supporting 2.0 and above
Mark M.
Messenger is nice for very tightly-scoped communications (i.e., for this operation, always let this specific Messenger know, so it can communicate back to this specific activity)
however, Messenger is a pain with configuration changes
(e.g., screen rotations)
Kevin M.
Ah, I started trying to use it but it was a bit complex
Mark M.
I'd lean towards broadcasts
if you don't need 1.5 compatibility
4:45 PM
Kevin M.
Right now I'm trying a regular binding service with a thread that does broadcasts
I'm waiting in the thread to keep from recreating the thread
Not sure if that's a good idea or not
Mark M.
you lost me
you mean that the thread is blocking on a LinkedBlockingQueue or something?
Kevin M.
Sorry, I have a regular Service that I bind to so that I can set another object to facilitate communication
No, the thread is just using the wait() method
Mark M.
all else being equal, I'm a fan of java.util.concurrent vs. arbitrary objects and wait()
I figure they did a lot more debugging that I can skip... :-)
Kevin M.
Do you think I should forgo the thread and just use and IntentService?
Mark M.
so, for example, you'll see in the Advanced Services chapter a service that uses a LinkedBlockingQueue for asynchronously executing Beanshell scripts
well, IntentService certainly simplifies a lot of stuff
if you do not need a multiple-thread pool, and it otherwise fits, I'd use IntentService
Kevin M.
ok
Mark M.
if you need lower-level control, rolling your own thread pool is certainly doable, but, again, I'd use the java.util.concurrent classes if they fit your needs
Kevin M.
Problem is that I'm sending a lot of information back and forth
4:50 PM
Mike
has left the room
Mark M.
that violates the "and it otherwise fits", so IntentService is out
IntentService is best for throw-it-over-the-wall stuff, with light feedback
not a rich two-way API
Kevin M.
I guess that's why I did the binding
Mark M.
binding is the only way to achieve that, painful as it is
and so rolling your own threads for background processing is probably the right answer
anybody else have a question?
Brian C.
yes, I do
Mark M.
fire away!
Brian C.
just noticed that you were speaking at the AnDevConf in March. Do you think this conference has a lot of value for an intermediate level developer?
Mark M.
will there be good content for the intermediate level developer? yes
is it worth the entrance fee? depends on whose money it is... :-)
it's put on by a professional media firm, and so it is pricier than I|O or a droidcon
4:55 PM
Brian C.
ok, that's helpful. Hope to see you there!
Mark M.
sounds good!
any other questions?
scott k.
quick one - do you know how to programatically turn off "screen lock" ?
or delay its timeout ?
Mark M.
I think there's something in Settings.System or Settings.Secure for that
if the latter, ordinary SDK apps can't change it
both of those are in the android.provider package
fitz
has left the room
scott k.
i don't want to unlock the phone, but my talking app gets terminated by the screen lock timeout
5:00 PM
Mark M.
talk faster
:-)
NetApex
has left the room
scott k.
it can wait for next time
Mark M.
anyway, that's it for today's chat
scott k.
has left the room
Mark M.
next one is Thursday, 8pm Eastern / 5pm Pacific
have a pleasant day!
Kevin M.
has left the room
Brian C.
has left the room
Mark M.
turned off guest access

Thursday, February 10

 

Office Hours

People in this transcript

  • Brian Cooley
  • David
  • fitz
  • Kevin Moore
  • Mark Murphy
  • Mike
  • NetApex
  • scott keller