Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 24 | 4:15 PM |
Justin M. | has entered the room |
Justin M. |
Hey there Mark!
|
Mark M. |
howdy, Justin!
|
Mark M. |
how can I help you today?
|
Justin M. |
Hey there, I don't think anything too complex today, just a question about Services and onStartCommand()
|
Mark M. |
fire away
|
Justin M. |
So when I have a Service (not an IntentService but
a regular Service) and I receive a command in onStartCommand(), if I
return Service.START_STICKY, if the process hosting the service is
killed in a low-memory situation, it should restart the service
automatically with the same intent that I last called startService()
with, right?
|
Mark M. |
no, that's START_REDELIVER_INTENT
|
Mark M. |
START_STICKY will restart you but will probably supply a null Intent
|
Justin M. |
Ahhhh, that's the problem then :-)
|
Justin M. |
Yes, exactly!
|
Justin M. |
That's the answer I was looking for :-)
|
Apr 24 | 4:20 PM |
Justin M. |
There was something else I was going to ask too,
but it's slipped my mind right now. I'll see if it comes back before
the end of the hour :-)
|
Mark M. |
OK
|
Apr 24 | 4:25 PM |
Justin M. |
Actually, let me make sure I understand something
correctly. So if I use START_REDELIVER_INTENT, if the OS kills the
process, it will always try to restart it with the last intent that was
delivered to it? (like maybe after a 5 second delay? I think I've seen
that in the device logs when a process hosting a service is killed?)
|
Mark M. |
I think it will redeliver all Intents you did not mark as having been processed
|
Mark M. |
and, AFAIK, it will always try to restart it
|
Mark M. |
no, I guess you're right -- you only get the last one
|
Justin M. |
Ahh, OK, great to know. I had originally thought
that I would need something to monitor the service to see if it was
still alive, like registering a repeating alarm with the AlarmManager as
a heartbeat mechanism...
|
Justin M. |
But I think that's not necessary at all with this, because the service will be restarted.
|
Mark M. |
that's the theory
|
Justin M. |
That works for now...
|
Justin M. |
I think I remember the second question too
|
Mark M. |
I avoid long-running services like the plague, so I don't have any hands-on experience with this scenario
|
Justin M. |
Yeah, it's not ideal, but it's definitely a requirement for this project :-/
|
Justin M. |
So I remember the second question now...
|
Justin M. |
Where is a good source of NFC tags? I want to
start playing with that, do you have any places you'd recommend that are
a good source?
|
Apr 24 | 4:30 PM |
Mark M. |
I bought a bunch from a variety of itty-bitty online shops
|
Mark M. |
that was a year or so ago
|
Mark M. |
not sure if anyone more substantial has entered the market
|
Justin M. |
So it's just random people selling them then?
|
Mark M. |
well, I suspect they're more than "random people", but not any name you'd recognize
|
Mark M. |
hold on while I find my NFC tag envelope...
|
Justin M. |
OK great
|
Mark M. |
I used BuyNFCStickers.com and Smartcardfocus.us with success
|
Mark M. |
I think I also bought from another little NFC firm, but I don't have the name handy
|
Justin M. |
OK great, I'll check then out. I was at a mobile
mondays talk last night where the presenter talked about NFC. They said
the tags have gotten cheaper recently, maybe around 50 cents/tag now.
Looked on amazon, they're more expensive there still
|
Mark M. |
I also bought from Touchatag, but that was before I
understood some of the nuances (e.g., whether a tag is rewriteable),
and their tags aren't that useful for me
|
Justin M. |
Oh, OK, good to know. I'll look at those two sources you mentioned earlier as a starting point, thanks for the info
|
Apr 24 | 4:35 PM |
tunneling | has entered the room |
tunneling |
Howdy tunneling!
|
Apr 24 | 4:40 PM |
Mark M. |
does tunneling often refer to tunneling in the third person? :-)
|
tunneling |
yes :)
|
tunneling |
How are things?
|
Mark M. |
sorry -- there's no beep on this thing when somebody enters the room, so if my eyes meander, I don't always notice
|
tunneling |
Not a problem.
|
Mark M. |
some things are fine, other things are less fine
|
Mark M. |
how can I help you today?
|
tunneling |
In Advanced Android, when talking about Remote Services (AIDL), you do a piece on a CallBack object... ring a bell?
|
Mark M. |
yes
|
tunneling |
I found this tutorial that does a typical Observer pattern by defining a listner aidl
|
tunneling |
do you know of any pitfalls to either method? I realize that could be a broad stroke question...
|
Mark M. |
well, "callback" and "listener" are largely interchangeable nouns, IMHO
|
Mark M. |
what specifically is different?
|
tunneling |
well.. good question.
|
Apr 24 | 4:45 PM |
tunneling |
oh, well.. in the "listener" tutorial, he has methods for adding and removing listeners
|
Mark M. |
ah
|
Mark M. |
ok
|
Mark M. |
whereas my callback was on a per-request basis, IIRC
|
tunneling |
yea
|
Mark M. |
the benefit of the per-request basis is that there is no GC risk
|
Mark M. |
you don't hold onto the callback very long in the service
|
tunneling |
ic
|
Mark M. |
explicit add/remove saves you a parameter, but if you forget to remove...
|
tunneling |
right...
|
Mark M. |
hence, I tend to prefer the per-request semantics, if there is a clear transactional feel to the API
|
Mark M. |
if, however, this is more of a true listener
(i.e., may get notified about lots of events happening over time), then
that per-request approach doesn't fly
|
tunneling |
yea, it would be asynchronous, sometimes often, and sometimes never
|
Mark M. |
that sounds like more of a listener pattern, or using something else (e.g., broadcast Intents)
|
Mark M. |
personally, I avoid binding where I can
|
Apr 24 | 4:50 PM |
tunneling |
so the Service will sometimes need to respond to a
Client's request, and at other times .. the Service would just need to
tell the Client that something happened.
|
tunneling |
Yea, I'm concerned with the Service getting killed and the Client not really knowing about it.
|
Mark M. |
unless the client also has a service, the client
is more likely to die off than is the service, outside of
task-killing/force-stopping
|
tunneling |
Oh? I'm not sure I understand..
|
Mark M. |
processes with a running service, on the whole,
are less likely to be killed off in the face of low memory than are
processes that only have activities
|
tunneling |
makes sense
|
tunneling |
the "Service" I've been discussing is a "Plugin", and is a different app.. using your Remote Views example as a starting point
|
Mark M. |
ah
|
Justin M. |
sorry to throw this in the middle, had one last
quick question that I wanted to get in the queue for if there's time
after tunneling is finished
|
Apr 24 | 4:55 PM |
Mark M. |
oh, go ahead
|
tunneling |
thanks Mark.. ttyl
|
Justin M. |
Question is about Parcelable types
|
Justin M. |
I know on the surface they look like a way to pass
objects around in Intents, but I think you said that isn't a good idea,
right?
|
Mark M. |
well, there are a few things here
|
Justin M. |
And also that serializing objects is costly and not recommended either?
|
Mark M. |
first, it's pass-by-value, not pass-by-reference
|
Mark M. |
(as is serializing, which is slower and adds no value for the Intent scenario)
|
Mark M. |
second, there are some occasions, particularly
with PendingIntents, where the OS seems like it wants to convert the
Parcelable back into an object for no good reason, and you crash
|
Mark M. |
third, it smacks of "I don't have a real data model, so I'll just keep passing my model around"
|
Justin M. |
So best to stick with primitive types in intents then, right?
|
Justin M. |
Or store complex objects as records in a database and pass the ID of that record around?
|
Mark M. |
yes and yes
|
Mark M. |
now, sometimes Parcelable is difficult to avoid
|
Justin M. |
Someone on my team is trying to use binding with
the service and pass around object instances. That really limits our
options, I don't want to do that
|
Mark M. |
my CWAC-Update module, for self-updating apps, needed to use Parceable to have an abstract strategy concept
|
Justin M. |
Is there a good place to read about Parcelable and when it's a good place to use it?
|
Apr 24 | 5:00 PM |
Justin M. |
(then I'm done :-) )
|
Mark M. |
not off the top of my head
|
Justin M. |
I haven't found anything either myself...
|
Justin M. |
OK, I'm set, thanks!
|
Mark M. |
no problem
|
Mark M. |
next chat is Thursday, 7:30pm Eastern
|
Mark M. |
have a pleasant day, all!
|
Justin M. |
You too!
|
Justin M. | has left the room |
tunneling | has left the room |
Mark M. | turned off guest access |