Nov 1 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 1 | 9:00 AM |
Lefko | has entered the room |
Lefko |
Hello
|
Lefko |
Am I early?
|
Mark M. |
no, sorry, I'm distracted
|
Mark M. |
how can I help you today?
|
Lefko |
npp
|
Lefko |
*np
|
Lefko |
thanks
|
Lefko |
anyway, I set up a Singleton for basic caching
|
Lefko |
and have been getting NPE's from time to time
|
Lefko |
is Singleton for cacheing not a good strategy?
|
Mark M. |
singletons for caching are fairly typical
|
Mark M. |
however, bear in mind that they only last as long as your process does
|
Lefko |
I watched your appinar about that topic
|
Mark M. |
if you are getting NullPointerExceptions, this suggests that you are assuming that your singleton is already created at points when it has not
|
Mark M. |
for example, suppose you have Activity A, B, and C, where A is the launcher
|
Mark M. |
in A, you set up the singleton
|
Mark M. |
user navigates from A, to B, to C, then presses HOME
|
Mark M. |
20 minutes pass
|
Mark M. |
during that time, your process was terminated to free up system RAM
|
Mark M. |
but then the user chooses your task from the overview screen
|
Lefko |
overview = task list?
|
Mark M. |
yes
|
Nov 1 | 9:05 AM |
Mark M. |
since the user was "recently" in the task, Android returns the user to C, not A
|
Nov 1 | 9:05 AM |
Mark M. |
but a fresh instance of C in a fresh process, since your process had been terminated
|
Lefko |
got it.
|
Lefko |
hmmm
|
Mark M. |
if C assumes that the singleton exists, boom
|
Lefko |
that sounds right
|
Mark M. |
the best approach is for the singleton to always be in position to be lazy-created
|
Lefko |
well the Singelton itself isnt null
|
Lefko |
its the data that Im assuming is there
|
Lefko |
well the singleton is being populated with data that I get from the server as a json
|
Lefko |
what do you think about saving the json as a string file and then reparsing it if any data is missing from teh singleton?
|
Mark M. |
saving the data locally (database, file, whatever) is also a typical approach
|
Mark M. |
whether that is simply a second level to the cache, or whether the local persistent store has greater meaning, depends a bit on the app
|
Lefko |
well this would be more of a fail safe in case the app was terminated
|
Lefko |
ok. I get it, thanks for the help!
|
Mark M. |
you're welcome!
|
Lefko |
one more question, is there a way to download the appinar content not directly from the app (ie so that I can watch it on my desktop)?
|
Nov 1 | 9:10 AM |
Mark M. |
not really
|
Mark M. |
I mean, the appinar content is a ZIP archive consisting of HTML slides, per-slide voiceover Ogg files, and related stuff
|
Mark M. |
the only player for it that I have written is in Android
|
Lefko |
alright, thanks anyway. They are a great extra to an already great resource!
|
Lefko |
have a great day
|
Mark M. |
you too!
|
Lefko | has left the room |
Nov 1 | 10:00 AM |
Mark M. | turned off guest access |
Nov 1 | 10:20 AM |
Mark M. | has left the room |
Nov 1 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 1 | 7:25 PM |
Steve S. | has entered the room |
Mark M. |
hello, Steve!
|
Steve S. |
Hi Mark!
|
Mark M. |
how can I help you today?
|
Steve S. |
I'll paste in my question:
|
Steve S. |
View paste
|
Mark M. |
that's reasonable
|
Steve S. |
Ok
|
Mark M. |
personally, I'd probably go gray and use a small indefinite ProgressBar
|
Steve S. |
ok
|
Steve S. |
Where would you put the ProgressBar?
|
Mark M. |
in the list row for that contact (assuming a list is the presentation, as your question indicates)
|
Mark M. |
just a small one, perhaps in the upper-right corner or something
|
Steve S. |
ok, that makes sense.
|
Mark M. |
I'd also tie any event listeners (e.g., clicks) to logic that will display a Toast or Snackbar or something saying "yo! I'm workin' here!" to explain why they cannot do what they would ordinarily do
|
Steve S. |
ok
|
Mark M. |
but that lets them continue using the rest of the app while you chug away at getting that individual item up to the server
|
Nov 1 | 7:30 PM |
Steve S. |
right
|
Steve S. |
ok, I'l work on something along those lines.
|
Steve S. |
A further issue I'm wondering about concerns the integrity of the local copies.
|
Steve S. |
There's an obvious concern about the local copy getting out of synch with the remote list. Do you have any suggestions on how to validate the integrity of the local copy?
|
Mark M. |
you use the term "integrity"
|
Mark M. |
I tend to reserve that term for things like data corruption
|
Mark M. |
is the data that you are now caching locally also being modified by other users, on the server?
|
Steve S. |
no
|
Mark M. |
OK
|
Steve S. |
i just need to make sure that the local copy accurately reflects the "master' list on the back-end.
|
Mark M. |
outside of error conditions, is there any scenario where you would expect it to be out of sync?
|
Steve S. |
Only if I make a programming error.
|
Mark M. |
for example, can the user modify this data through some other UI (e.g., Web app)?
|
Steve S. |
no
|
Mark M. |
so... why is the server the 'master', versus just a backup?
|
Nov 1 | 7:35 PM |
Mark M. |
is there additional stuff going on in the server other than just warehousing this data?
|
Steve S. |
I think I'm making this sound more complicated than it is.
|
Steve S. |
I just need to make sure the local list is the same as the remote list.
|
Steve S. |
The only way they would end up diverging is if I make a programming error.
|
Mark M. |
well, if your only concern are unhandled exceptions and other errors like that, allow the user to "refresh" or "download" or "sync" or "repair" from your UI
|
Mark M. |
where that downloads the data from the server and does a total replacement of the local copy
|
Steve S. |
ok
|
Mark M. |
only offer that when other REST operations are not in flight (e.g., disable the action bar item when you're processing transactions)
|
Steve S. |
ok
|
Mark M. |
IMHO, your terminology should reflect where the *user* thinks the "system of record" is
|
Steve S. |
ok
|
Mark M. |
if the user thinks that the real data is on the device, and the server is holding a backup, use terms like "restore" for replacing the local copy with the server copy
|
Mark M. |
if the user thinks that the real data is on the server, that's where "refresh", "download", etc. would work
|
Nov 1 | 7:40 PM |
Steve S. |
All right. I'll work on this approach.
|
Steve S. |
No more questions today. Thank you so much for your help!
|
Mark M. |
you're welcome!
|
Steve S. |
Have a good evening, Mark!
|
Mark M. |
you too!
|
Steve S. | has left the room |
Nov 1 | 8:25 PM |
Mark M. | turned off guest access |