Office Hours — Today, October 2

Tuesday, September 30

Oct 2
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
Gabriele
has entered the room
Mark M.
hello, Gabriele
Gabriele
hi Mark
Mark M.
how can I help you today?
um, do you have a question? or are you just hanging out? :-)
Gabriele
I've noticed that if I press Home button and then go back to the activity, using the stack, fragments of the viewpager are automatically reloaded, but if I press Home button and go back to the app, using my notify icon, then fragments are not reloaded
eheh, yes
7:35 PM
Gabriele
is this due to lifecycle?
Mark M.
by "notify icon", do you mean a Notification?
Gabriele
yes, I have a "permanent" Notification icon
Mark M.
unless you do something in the Intent or in the manifest, that Notification will launch another instance of your activity
Gabriele
in my manifest I have: android:launchMode="singleInstance"
Mark M.
sorry, I haven't played around with that
Gabriele
should I use something like addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)?
oh, sorry
Mark M.
singleTask and singleInstance "are not appropriate for most applications" (quoting the docs)
Gabriele
will try to play with intent's flags
Mark M.
I'd go with Intent flags, though which ones will depend a bit on your overall circumstance
7:40 PM
Mark M.
it would be either the one you list, or the combination of FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK
Gabriele
oh thank you, will try it, too. Another question, currently I'm starting my service from the activity onCreate, anyway I think this is a bad thing, because there is the risk that if onCreate gets called again, I get onStartCommand called twice
have you got some suggestion about it?
Mark M.
um, is there a particular problem with onStartCommand() being called twice?
Gabriele
not now, but I tought it was a bad thing
(from a design point of view)
Mark M.
well, in the command pattern for working with services, onStartCommand() may be called lots of times
and in the binding pattern for working with services, onStartCommand() may never be called
so, any value from 0 to N calls is valid
whether it makes sense for your situation, I can't say, as I don't know your app
Gabriele
considering that my service keep the connection to the irc server, adds data to my model and so on
would binding pattern be better?
Mark M.
I can't tell you if it will be better, as I have no basis for comparison -- again, I don't know your app
7:45 PM
Mark M.
I am merely saying that having onStartCommand() be called twice is not intrinsically a problem
Gabriele
in general when is binding pattern preferred to the other?
Mark M.
well, I generally prefer the command pattern
as I like loosely coupled components
and binding is rather tight coupling
it also represents more state you have to manage (e.g., via a retained fragment to deal with configuration changes)
however, you get a "real" API versus just sending commands via startService()
Gabriele
ah, I see
Mark M.
you might want to read through the chapters on services in the book -- I go into the details of both patterns
Gabriele
yes, thank you as always
I will read about these things to understand better which are my needs :)
7:50 PM
Gabriele
have a good evening (if it is, to you), Mark
7:50 PM
Mark M.
you too!
Gabriele
we will see the next time, probably :P
Mark M.
next one is Wednesday, 7:30pm US Eastern Time
8:30 PM
Gabriele
has left the room
Mark M.
turned off guest access

Tuesday, September 30

 

Office Hours

People in this transcript

  • Gabriele
  • Mark Murphy