Office Hours — Today, March 3

Thursday, March 1

Mar 3
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:15 AM
Jan
has entered the room
Mark M.
hello, Jan!
how can I help you today?
Jan
Hello
I've been working on app where I'd like to store some values via SharedPrefs
but I deciced to wrap geta nd set part to separate class ( for easier access)
but there's a question
when I want to use app refs (or global) via getDefaultSharedPreferences
9:20 AM
Jan
I have to pass app context
And finally, my question is.
Is it ok to store app context there or are there any situations when it changes
Mark M.
if by "app context", you mean the Application instance (from getApplication() or getApplicationContext()), it is a singleton
it will be created when your process is created
and it lives as long as your process does
so, it will not change while your process is running
Jan
I see
and one more question regarding activity/fragment lifecycles
9:25 AM
Jan
I was searching for some , let's say more complete diagrams (and found some). But still I miss some explanation on when and why some of state changes happen
And google site for android devs does not contain details
so I ended with this
Is there any better source for this?
except Log.d way
Mark M.
if you are asking how one could prove that the diagram is accurate, at *best*, Log.d() could help
there are many edge and corner cases
and the source code is very confusing
on the whole, I only worry about ~50% of the callbacks listed in that diagram
Jan
yes, I'm actually using it. But I miss quick reference for situations like: "if you turn off display on phone the this chains is called".
9:30 AM
Mark M.
well, the answer for something like that probably varies between OS versions, and *possibly* by device (for manufacturer tweaks)
Jan
I see (and I wanted to ask the same thing)
Mark M.
trying to optimize things for specific scenarios like that will cause you many sleepless nights
Jan
so every type of device can react deifferently
Mark M.
in theory, yes
in practice, I expect that the *vast* majority of devices probably behave in 1-2 ways
with a few devices acting strangely
and some devices in which the whole question needs to be revisited (e.g., Chrome OS, Android TV)
this is why I try not to optimize for scenarios like that, as while usually you can solve it for many devices easily, handling the "long tail" of devices is a problem
Jan
ok, thanks a lot and have a nice day
Mark M.
you too!
Jan
has left the room
9:55 AM
Mark M.
turned off guest access

Thursday, March 1

 

Office Hours

People in this transcript

  • Jan
  • Mark Murphy