4

Is there any way to listen to such an event?

I have a custom EditText, which shows a FragmentDialog if it is clicked to pick a time, distance or a number, depending on the EditText setup...

Now I'm using event bus based FragmentDialogs in my whole application and I want to register the view on the bus and unregister it, if the view is destroyed...

But I don't know, where I could unregister it...

prom85
  • 16,896
  • 17
  • 122
  • 242
  • 1
    onDetachFromWindow could be one. see https://plus.google.com/u/0/+ArpitMathur/posts/cT1EuBbxEgN – njzk2 Nov 13 '13 at 14:04
  • that's what I'm testing right now... but I'm not sure if this always works, I already read something about this function not always being called... – prom85 Nov 13 '13 at 14:05

1 Answers1

2

A View is added over your activity/fragment/Dialog etc. Therefore it doesn't have its own onDestroy alike event. So instead, use activity's/fragment's onDestroy method to identify when the View is not valid anymore.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • 1
    I know that... What I want is a independent view, which handles it's dialogs itself (what I already have), but I don't want to make an WeakReference bus to handle my views... therefore, and only for this bus system, I need to unregsiter the view before it get's destroyed... onDetachFromWindow seems to work so far... – prom85 Nov 13 '13 at 14:14
  • 1
    btw, I'm including them sometimes in xml as well, and I don't know, if the view is part of an activity or fragment... of course, I could iterate over all views in the `onDestroy` of the fragment/activity as well, but that seems to be just a workaround... – prom85 Nov 13 '13 at 14:17