Office Hours — Today, November 1

Yesterday, October 31

Nov 1
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Lefko
has entered the room
Lefko
Hello
Am I early?
Mark M.
no, sorry, I'm distracted
how can I help you today?
Lefko
npp
*np
thanks
anyway, I set up a Singleton for basic caching
and have been getting NPE's from time to time
is Singleton for cacheing not a good strategy?
Mark M.
singletons for caching are fairly typical
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
for example, suppose you have Activity A, B, and C, where A is the launcher
in A, you set up the singleton
user navigates from A, to B, to C, then presses HOME
20 minutes pass
during that time, your process was terminated to free up system RAM
but then the user chooses your task from the overview screen
Lefko
overview = task list?
Mark M.
yes
9:05 AM
Mark M.
since the user was "recently" in the task, Android returns the user to C, not A
9:05 AM
Mark M.
but a fresh instance of C in a fresh process, since your process had been terminated
Lefko
got it.
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
its the data that Im assuming is there
well the singleton is being populated with data that I get from the server as a json
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
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
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)?
9:10 AM
Mark M.
not really
I mean, the appinar content is a ZIP archive consisting of HTML slides, per-slide voiceover Ogg files, and related stuff
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!
have a great day
Mark M.
you too!
Lefko
has left the room
10:00 AM
Mark M.
turned off guest access
10:20 AM
Mark M.
has left the room
7:20 PM
Mark M.
has entered the room
Mark M.
turned on guest access
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:
View paste
We spoke last week about maintaining a local copy of a contact list that can be updated immediately and displayed to the user while waiting for a Rest request to delete a contact on the back-end to complete. If the user deletes a contact, the contact is removed immediately from the list displayed to the user but restored if the Rest request fails.

I am wondering how to handle the case where the user adds a contact. The contact should be added to the list immediately so the user will know not to try to add it again. But there are operations that can't be carried out, such as calling the contact, until the Rest request to add it on the back end completes. I am wondering how to indicate to the user both that the contact has been added but also that he can't call it while the Rest request is being processed.

The solution I've thought of is to add the contact to the list shown to the user but to grey it out or to append "(pending)" to the contact name until the Rest request completes. Is this reasonable? Is there a better approach?
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
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)
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
7:30 PM
Steve S.
right
ok, I'l work on something along those lines.
A further issue I'm wondering about concerns the integrity of the local copies.
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"
I tend to reserve that term for things like data corruption
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?
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.
I just need to make sure the local list is the same as the remote list.
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
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
if the user thinks that the real data is on the server, that's where "refresh", "download", etc. would work
7:40 PM
Steve S.
All right. I'll work on this approach.
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
8:25 PM
Mark M.
turned off guest access

Yesterday, October 31

 

Office Hours

People in this transcript

  • Lefko
  • Mark Murphy
  • Steve S