Office Hours — Today, April 3

Saturday, March 31

Apr 3
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:55 AM
gonzobrains
has entered the room
gonzobrains
hi.
Mark M.
hello, gonzobrains!
gonzobrains
Sorry I am late.
Mark M.
that's OK -- do you have a quick question?
gonzobrains
Yes.
I am having trouble with fragments remaining on the screen after resuming an app that was paused. If the user tries to use them it causes the app to crash. In one case I manage to call the fragment's Dismiss() when the Activity's OnPause() is called. This works for that particular case, but often times OnPause() doesn't get called.
So now I have to troubleshoot both these "ghost" fragments and why OnPause() isn't getting called in the first place. Any ideas?
Mark M.
nothing leaps to mind
all attached fragments should get the same lifecycle events as their enclosing activity
gonzobrains
that's what I thought.
Mark M.
if you are not getting lifecycle events, perhaps the fragment is no longer attached
gonzobrains
I think that may be the case.
Mark M.
in terms of "remaining on the screen", perhaps there is something in how the fragment sets up the UI, where it goes behind the activity's back (e.g., directly adds widgets to containers)
gonzobrains
I will look into that. I inherited this code so I am not completely familiar with the design.
Mark M.
ah
10:00 AM
Mark M.
for example, make sure that if it inflates a layout, it uses the three-parameter inflate() method, and passes false for the third parameter
gonzobrains
The design relies on a single activity which just displays fragments for each thing the app needs to do.
and certain fragments display yet another fragment that acts as a drop-down.
Mark M.
I haven't seen that drop-down technique used before
at the fragment level, that is
gonzobrains
if that dropdown is displayed when the user puts the phone to sleep, it will still be displayed when the app resumes despite its "parent" fragment having gone away already.
yeah, me neither.
I think it is basically a listview within a fragment. and an edit text to search within it.
Mark M.
there may be something screwy with how that drop-down is being implemented, but it's tough for me to say exactly how it is going haywire
gonzobrains
on one screen, I can call that "drop down" fragment's Dismiss() when the parent fragment's OnPause() is called. That cures it. But for some reason not all screen fragments get their OnPause() called for some reason.
Mark M.
add some logging to onAttach()/onDetach() and see what turns up
gonzobrains
ahh, okay.
Mark M.
and see how the drop-down fragment is doing its UI
gonzobrains
I logged all the OnPause/OnStop/OnDestroy methods but not attach/detach.
i will see if I can this.Dismiss() the drop-down fragment on OnDestroy
Mark M.
dismiss() is the sort of thing that I associate with a DialogFragment, but if you're using a DialogFragment for a drop-down, it may be trying to do some fancy footwork to arrange to display the drop-down window in the right spot
gonzobrains
i'm sorry I meant OnDetach()
Mark M.
and it may be that the "fancy footwork" has bugs
gonzobrains
yes, I believe the drop-down is derived from DialogFragment
Mark M.
there are lots of expandable-view libraries on the Android Arsenal
you might wind up switching to one of those, rather than trying to have a DialogFragment serve in that role
10:05 AM
Mark M.
anyway, that's a wrap for today's chat
gonzobrains
yeah that's a good idea.
Mark M.
the transcript will be posted to https://commonsware.com/office-hours/ in a bit
gonzobrains
thanks.
ok thanks again.
Mark M.
you're welcome!
the next chat is tomorrow at 7:30pm US Eastern
have a pleasant day!
gonzobrains
you, too!
gonzobrains
has left the room
Mark M.
turned off guest access

Saturday, March 31

 

Office Hours

People in this transcript

  • gonzobrains
  • Mark Murphy