Can a custom View know that onPause has been called?

后端 未结 6 2162
南方客
南方客 2021-02-03 18:52

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

6条回答
  •  执笔经年
    2021-02-03 19:08

    If you simply override the View class and create your own CustomView you could create a interface to act as a listener, which should be implemented by you parent activity, so when something happens you trigger the event and establish the communication between those components back and forth.

    Depending on what you want to achieve, Fragments could be useful since this component has your own lifecycle similar to activity (onPause/onResume for instance) , holds your own state, either has or not a view and could retain their state between configuration chamges.

    See more in: http://developer.android.com/reference/android/app/Fragment.html http://developer.android.com/guide/components/fragments.html

提交回复
热议问题