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
|
Feb 15 | 4:00 PM |
Mark M. |
howdy, Scott!
|
Mark M. |
Kevin, you got in first...do you have a question?
|
Kevin M. |
Just going to listen for now
|
Mark M. |
OK
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
in terms of new stuff, it is over-complete -- I suspect they are still deciding what is baked enough that they're leaving in
|
Mark M. |
however, the preview SDK appears to be missing Google Maps and such
|
Mark M. |
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
|
Feb 15 | 4:05 PM |
Kevin M. |
Since no one has a question, I'll ask one
|
Kevin M. |
I'm still having problems with Activities and the singleTop, singleTask settings
|
Kevin M. |
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
|
Mark M. |
why?
|
Mark M. |
(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
|
Kevin M. |
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
|
Mark M. |
static data members are static
|
Mark M. |
they live outside any given instance of any class
|
Mark M. |
semantically, they're globals
|
Mark M. |
now, if the process goes away (e.g., user presses HOME and hours elapse), the statics go away as well
|
Mark M. |
which is why they're fine for caches
|
Mark M. |
but they are no substitute for a persistent data model
|
Feb 15 | 4:10 PM |
Kevin M. |
Should an activity be just a light-weight container for a view?
|
Kevin M. |
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)
|
Mark M. |
strategically, there may be reasons for having them as separate activities
|
Mark M. |
I just blogged a bit in this area: http://commonsware.com/blog/2011/02/14/nat…
|
NetApex |
Ahh nice timing
|
NetApex |
Ok going to go have a read really fast
|
Mark M. |
meanwhile...
|
Mark M. |
Kevin, do you have a question?
|
Kevin M. |
So many questions....
|
Mark M. |
oh, wai, sorry
|
Mark M. |
mixed names up
|
Mark M. |
trying to get the newcomers
|
Mark M. |
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
|
Feb 15 | 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()
|
Mark M. |
there is no onMessage() of C2DMBaseReceiver, except as an abstract method declaration
|
Mark M. |
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
|
Mark M. |
Chapter 20 of _The Busy Coder's Guide to Advanced Android Development_ IIRC
|
David |
Thanks
|
Mark M. |
Mike, do you have a question?
|
Mark M. |
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 :-)
|
Feb 15 | 4:20 PM |
Mark M. |
there is no such concept as "does not respond to onDestroy()"
|
Mark M. |
if you do not override it, the implementation in Service gets called
|
Mark M. |
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()
|
Mark M. |
either use the command pattern (i.e., send data via startService())
|
Mark M. |
or use both startService() *and* the binding pattern
|
Mark M. |
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
|
Mark M. |
do not start services without a clear picture of concretely when you will end them
|
Mark M. |
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
|
Feb 15 | 4:25 PM |
Mark M. |
(Mike: scroll up in the chat log -- the messages should be there, no?)
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
no, you can't use that combination
|
Mark M. |
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
|
Mark M. |
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
|
Kevin M. |
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
|
Mark M. |
it just terminates the component
|
David | has left the room |
David | has entered the room |
Feb 15 | 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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
it's been 11 years since I did any serious C/C++ work
|
Mark M. |
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"
|
Mark M. |
except in rather unusual circumstances (e.g., VOIP client)
|
Mark M. |
JNI doesn't really influence that one way or another
|
Feb 15 | 4:35 PM |
Mark M. |
checking periodically, ideally with a configurable period, is more in line with Android development models
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
off is off
|
Mike |
well, yes
|
Mike |
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
|
Mark M. |
AlarmManager, wake up every so often, look for images
|
Mark M. |
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
|
Feb 15 | 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
|
Mark M. |
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!
|
Mark M. |
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.
|
Mark M. |
however, for Android 1.5, it is always a true broadcast, to the whole device
|
Mark M. |
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)
|
Mark M. |
however, Messenger is a pain with configuration changes
|
Mark M. |
(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
|
Mark M. |
if you don't need 1.5 compatibility
|
Feb 15 | 4:45 PM |
Kevin M. |
Right now I'm trying a regular binding service with a thread that does broadcasts
|
Kevin M. |
I'm waiting in the thread to keep from recreating the thread
|
Kevin M. |
Not sure if that's a good idea or not
|
Mark M. |
you lost me
|
Mark M. |
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
|
Kevin M. |
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()
|
Mark M. |
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
|
Mark M. |
well, IntentService certainly simplifies a lot of stuff
|
Mark M. |
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
|
Feb 15 | 4:50 PM |
Mike | has left the room |
Mark M. |
that violates the "and it otherwise fits", so IntentService is out
|
Mark M. |
IntentService is best for throw-it-over-the-wall stuff, with light feedback
|
Mark M. |
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
|
Mark M. |
and so rolling your own threads for background processing is probably the right answer
|
Mark M. |
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
|
Mark M. |
is it worth the entrance fee? depends on whose money it is... :-)
|
Mark M. |
it's put on by a professional media firm, and so it is pricier than I|O or a droidcon
|
Feb 15 | 4:55 PM |
Brian C. |
ok, that's helpful. Hope to see you there!
|
Mark M. |
sounds good!
|
Mark M. |
any other questions?
|
scott k. |
quick one - do you know how to programatically turn off "screen lock" ?
|
scott k. |
or delay its timeout ?
|
Mark M. |
I think there's something in Settings.System or Settings.Secure for that
|
Mark M. |
if the latter, ordinary SDK apps can't change it
|
Mark M. |
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
|
Feb 15 | 5:00 PM |
Mark M. |
talk faster
|
Mark M. |
:-)
|
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
|
Mark M. |
have a pleasant day!
|
Kevin M. | has left the room |
Brian C. | has left the room |
Mark M. | turned off guest access |