Mar 3 |
8:55 AM |
Mark M. |
has entered the room |
Mark M. |
turned on guest access |
Mar 3 |
9:15 AM |
Jan |
has entered the room |
Mark M. |
hello, Jan!
|
Mark M. |
how can I help you today?
|
Jan |
Hello
|
Jan |
I've been working on app where I'd like to store some values via SharedPrefs
|
Jan |
but I deciced to wrap geta nd set part to separate class ( for easier access)
|
Jan |
but there's a question
|
Jan |
when I want to use app refs (or global) via getDefaultSharedPreferences
|
Mar 3 |
9:20 AM |
Jan |
I have to pass app context
|
Jan |
And finally, my question is.
|
Jan |
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
|
Mark M. |
it will be created when your process is created
|
Mark M. |
and it lives as long as your process does
|
Mark M. |
so, it will not change while your process is running
|
Jan |
I see
|
Jan |
and one more question regarding activity/fragment lifecycles
|
Mar 3 |
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
|
Jan |
And google site for android devs does not contain details
|
Jan |
so I ended with this
|
Jan |
|
Jan |
Is there any better source for this?
|
Jan |
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
|
Mark M. |
there are many edge and corner cases
|
Mark M. |
and the source code is very confusing
|
Mark M. |
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".
|
Mar 3 |
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
|
Mark M. |
in practice, I expect that the *vast* majority of devices probably behave in 1-2 ways
|
Mark M. |
with a few devices acting strangely
|
Mark M. |
and some devices in which the whole question needs to be revisited (e.g., Chrome OS, Android TV)
|
Mark M. |
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 |
Mar 3 |
9:55 AM |
Mark M. |
turned off guest access |