Office Hours — Today, August 16

Saturday, August 13

Aug 16
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Steve S.
has entered the room
Mark M.
hello, Steve!
how can I help you today?
Steve S.
Hi, Mark!
I'll paste in a question:
Is there any problem with making an activity singleTop? Is that something I should avoid?
Mark M.
I am not aware of any particular problems
7:30 PM
Steve S.
Ok.
Mark M.
though the key is that the activity has to be at the top of the task
if it is not at the top of the task, AFAIK singleTop has no effect, behaving like standard instead
ndrocchietto_ivano
has entered the room
Mark M.
that may or may not be a problem, depending upon the various ways that the user might navigate into your app
the _TOP flags (FLAG_ACTIIVTY_CLEAR_TOP, FLAG_ACTIVITY_SINGLE_TOP) have a similar limitation, IIRC
Steve S.
I'm not sure I understand. I have an activity I've made singleTop. It's the child of another activity and has children of its own. It does retain values when I return to it from it's children. Is your point that if I were to go to the singleTop activity twice from it's parent, that it would not retain values in that case?
Mark M.
no, that's not what I mean
(BTW, Ivano, I will be with you shortly)
ndrocchietto_ivano
( enjoying...)
Mark M.
given your paragraph, let's say that we have Activity A, B, and C
A starts B, B starts C
Steve S.
ok
Mark M.
B is where your singleTop is
the only place where singleTop plays a role is when something calls startActivity() to start up that activity
so, if the user presses BACK from C to return to B, whether B is singleTop or not does not matter
Steve S.
ok
Mark M.
but, if in C, you call startActivity() to start up B, you might think that singleTop would return you to your existing B instance
however, it shouldn't
7:35 PM
Mark M.
because B is not at the top of the task -- A is
C would create a new instance of B, giving us A -> B -> C -> B in our task
Steve S.
Ok. I think I see what you mean. But that doesn't apply using up navigation in C or calling finish() in C. Is that right.
Mark M.
definitely finish()
er, definitely finish() is not affected by singleTop
up navigation makes my head hurt, so I am uncertain what happens there
ndrocchietto_ivano
( eh eh what a topic)
Steve S.
Ok. My impression at this point is that using either up navigation from C or calling finish in C, B retains it's values if it's singleTop.
Mark M.
if you finish() in C, it does not matter what the launchMode is
Steve S.
ok
Mark M.
it is still the same instance of B regardless
Steve S.
ok - i see
Mark M.
again, launchMode only affects startActivity() calls
Steve S.
ok. I think I understand
Mark M.
I'm hazy as to the conditions when up navigation will use startActivity(), which is why I don't know if singleTop is important there or not
Steve S.
I see.
Mark M.
let me take a question from Ivano, and I will be back with you in a bit
Ivano: your turn! do you have a question?
Steve S.
Sure
ndrocchietto_ivano
yes thanks, Hey Steve!.
I have exceptionally before a metaquestion
Steve S.
hi ivano!
7:40 PM
ndrocchietto_ivano
View paste
is stupid but I want to take advantage of your knowledge on that. ust because i need an internal (psychological)guideline,
leaving all the relativity of a medior and senior position
understanding a "mindmap" legacy code( a git clone of a mindmap project), in particulary A) how the single nodes, bullets are inserted into the canvas,
and B)how are allocated in hashmaps, arraylists etc, the various children parents
is more a medior or a senior task?
Mark M.
I honestly have no idea
ndrocchietto_ivano
:)
OK ball to Steve!
Mark M.
um, OK
Steve S.
I'll paste a follow-up question:
If I pass intent extras to a singleTop activity when starting it, are there any cases where those extras would cease to be available (e.g. if a user navigates away from the activity and then back to it, or if the OS kills the activity due to low memory)?
Mark M.
well, there are extras, and there are extras :-)
Steve S.
ok
Mark M.
in general, extras will not be lost, regardless of launchMode
whatever extras were on the Intent when the activity was created will still be there, regardless of configuration changes and such
Steve S.
right
Mark M.
if the user leaves the app via HOME/RECENTS/something, and the activity is still running, and the app's process is terminated, and the user returns soonish (<30 minutes), so Android re-creates your activity... you still have your extras
Steve S.
ok
Mark M.
if the user leaves the app for an extended period, such that even if the user returns to the app from the overview screen/recent-tasks list, the user will go back to your launcher activity, as if they tapped on the home screen launcher icon
so, in that scenario, extras are "lost", but so is the whole running state of the app
(exception: PersistableBundle on Android 5.0+, though I haven't played with that much)
Steve S.
So in that case it starts all over from the main activity?
Mark M.
yes
now, in the specific case of singleTop, there may be two Intents' worth of extras to consider
7:45 PM
Mark M.
there is the Intent used to create the activity, which you get via getIntent()
however, if you are later called with onNewIntent() -- because your activity was at the top of the task, and some other activity tried starting it -- you get passed in the Intent for that later startActivity() call
this is *not* the Intent returned by getIntent(), which is always the Intent used to create the activity
the Intent used to return to the running singleTop instance of the activity is just passed into onNewIntent(), and it's up to you to hold onto anything in there yourself, such as extras
Steve S.
ok. the case I found where the extras were lost was when i navigated from A to it's child B and then up navigated back to A. If I make A singleTop, I can up navigate back from B to A and the extras are still there.
ndrocchietto_ivano
(shared PReferences...)
Mark M.
unless A was finish()'d, I am not sure how that would have occurred
but, then again, up navigation still makes my head hurt
Steve S.
you mean how the extras would have been lost?
Mark M.
correct
that would imply that up navigation created a fresh instance of A, rather than just returning to the existing instance
and I would have hoped that up navigation was more intelligent than that
Steve S.
ok. then a more general question: what's the best way to insure that the extras used to start an activity will always be available?
Mark M.
hold onto the data yourself somewhere
Steve S.
ok.
Mark M.
for a given activity logical instance, the extras can't be lost, any more than the saved instance state Bundle can be lost
Steve S.
right
Mark M.
if you are finding scenarios where extras are missing, that implies that you have a new logical instance of the activity
Steve S.
ok
7:50 PM
Mark M.
that means one of two things:
1. you need to revise your navigation to not create a new logical instance where you're not expecting it, or
2. you need to save the information somewhere else that lies outside the activity logical instance
some sort of singleton manager object if the data only needs to be in RAM, or in a persistent store if the data needs to survive process termination
personally, I would focus on #1
Steve S.
ok
ndrocchietto_ivano
( too much curious global static variable is bad vs singleton for you?)
Mark M.
Ivano: Android uses statics/singletons more than in classic Java, due to the Android component architecture
ndrocchietto_ivano
OK
Mark M.
the classic issues remain, such as potential memory leaks
ndrocchietto_ivano
I see thanks
Mark M.
we just have to deal with them, rather than enact a blanket ban on statics/singletons
ndrocchietto_ivano
i am a fun of the K values of shared preferences to bring variables trough the classes, are so easy
fan*
Mark M.
yes, but SharedPreferences are persistent, so you are incurring disk I/O along the way
ndrocchietto_ivano
ah ja!
did not think over
so true and inefficient for temporary variable in the buffer
7:55 PM
ndrocchietto_ivano
anyway I would love to ask you my real question
Mark M.
Steve: let me turn to Ivano for a bit, and I'll be back with you shortly
Ivano: go right ahead
Steve S.
sure
ndrocchietto_ivano
my eyes want to sleep in amsterdam.thanks Mark and Steve
ctrl V
View paste
the question is easy but need to be sure on that, and is over GIT. This mind map cloned is difficult so i created a branch of the first commit( that is the easiest one), git branch -b myName hashNameFirstCommit. 

Now what is the best way to proceed to save my branch, I should just do an ADD and a COMMIT I guess. Now the problem is when I want to see the second commit this mindmap developer did, which step I should do with the previous branch, 
WHAT HAPPENS if i merge my branch to master? I would like to OVERWRITE THE FIRST COMMIT made by the user, but I guess Linus Torvalds decided that GIT does not work like that..
Mark M.
um, I can help you with Android app development questions
for Git advice, you will need to find another expert
ndrocchietto_ivano
OK
OK will try with some code fellow that work in continuos integration
well have a nice night
and see you soon, thanks
Steve S.
you too!
Mark M.
I am sorry that I could not be of more use to you today
ndrocchietto_ivano
I am happy Mark that you are human
Mark M.
Steve: OK, back to you -- do you have another question?
Steve S.
ok. I think I have a better understanding of the situation. I'll simply provide defaults in the cases where the expected intent extras aren't there. That will work for this application.
By the way, I wanted to let you know I just renewed my subscription because you've been so helpful over the past year.
Mark M.
thanks!
Steve S.
Thanks so much, and have a good evening!
Mark M.
you too!
Steve S.
has left the room
8:00 PM
Mark M.
Ivano: if you are still around and have an Android question, go right ahead
8:10 PM
ndrocchietto_ivano
has left the room
8:25 PM
Mark M.
turned off guest access

Saturday, August 13

 

Office Hours

People in this transcript

  • Mark Murphy
  • ndrocchietto_ivano
  • Steve S