I have a custom View that runs a Thread operation which sits around making calls to the interwebs periodically. I would like to know if there\'s a way for me to not have to kil
Not unless you notify it directly.
For your purpose, override View.onDetachedFromWindow()
and relinquish your Thread there. Then, when the view is visible again, spin the Thread back up in View.onAttachedToWindow()
. The problem with onPause() and onResume() is that you can still have a view that's visible on screen, but is attached to a paused Activity. An example of when this can happen is if you have one Activity in a window that overlays another.
Or, as william gouvea suggests, a Fragment might be better suited for your purpose since it already has the life-cycle hooks for pause and resume, and anything that talks to the network really falls in the controller realm anyway.