Office Hours — Today, November 13

Saturday, November 10

Nov 13
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:55 PM
Aaron
has entered the room
Mark M.
hello, Aaron!
how can I help you today>
(give or take some punctuation...)
Aaron
hello again Mark, 3 questions today:
in descending order of priority
View paste (2 more lines)
1. I was able to identify that SwipeRefreshLayout leak. What was roughly happening was that I was storing a View in an instance variable of the fragment, so when it got replace()'d, it was detached but the fragment instance was still alive on the backstack, so the instance variable was holding onto the view past onDestroyView(). I also eliminated another very similar leak of my RecyclerView.Adapter that was being caused by the data binding class holding onto references in basically the same way. All in all I learned a lot about memory management and lifecycles, so that's good. But it raised one question - I had previously thought that onDestroy() was when a fragment's instance was released, but I recently learned that onDetach() is called after onDestroy(), which implies that I was wrong. (I wouldn't have had those leaks, if the instance were freed in onDestroy()). So when exactly is the instance freed, then, and what exactly happens in onDestroy() if not that?

2. I'm implementing an uncaught exception handler and a routine to let users email me crash logs, like you suggest in your Distribution chapter. You can see the relevant methods here: https://github.com/ajh3/NoSurfForReddit
...
Mark M.
taking them in reverse order based on simplicity...
Aaron
sure
Mark M.
3. do something that the user needs to acknowledge
that could be a dialog, a snackbar with an action, or something inline in the UI of your app
8:00 PM
Mark M.
I'm also not a tremendous fan of Toast-spamming a user, repeatedly showing a Toast based on intermediate errors
only bother the user when you give up based on your retry policy, and then use something that the user has to acknowledge
2. please OMG please use some existing code for this
I am a fan of ACRA, but if you prefer some commercial service (e.g., Fabric) that's OK too
Aaron
OK that seems reasonable, I'll put that on my list of things to do after first release (re: getting rid of toasts)
ah, OK, it seemed like a simple enough task
why OMG, lol?
Mark M.
the app is in a fairly precarious state when an exception gets to the uncaught exception handler, and so getting this right is a fair bit of work
Aaron
I see
Mark M.
if ACRA's delivery options don't fit the bill, you can write a plugin
Aaron
I will look into ACRA
Mark M.
that allows ACRA to handle all the nasty stuff and you just get the exception information where you want it to go
and I have a chapter on in the book
Aaron
OK, great
Mark M.
1. fragment lifecycles are a mess
er, top-down flow
8:05 PM
Mark M.
in terms of the problem that you describe, I haven't run into that, but that may be some combination of the specific things that I have done and changes in how the support library fragments work
Aaron
OK, so to put my question more simply, I'm just confused why onDestroy() and "Fragment is destroyed" are not the same box
and what is onDestroy(), then
Mark M.
¯\_(ツ)_/¯
Aaron
lol, fair enough
Mark M.
frankly, that diagram and the overall flow makes no sense to me
and I run into the same sorts of confusion that you do
onDestroy() should be called after onDetach(), in a sane world
Aaron
alright, thanks for the info
Mark M.
they're trying to stick with an API that they created in 2011 and probably regret in places
Aaron
that's all I've got for now, I'll get to work on ACRA
thanks for the help!
Mark M.
OK
you're welcome!
8:10 PM
Aaron
has left the room
8:30 PM
Mark M.
turned off guest access

Saturday, November 10

 

Office Hours

People in this transcript

  • Aaron
  • Mark Murphy