Can a custom View know that onPause has been called?

后端 未结 6 2164
南方客
南方客 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:12

    if Build.VERSION.SDK_INT < Build.VERSION_CODES.N

    @Override
    protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
        super.onVisibilityChanged(changedView, visibility);
        if (visibility == View.VISIBLE) //onResume called
        else // onPause() called
    }
    

    then Build.VERSION.SDK_INT >= Build.VERSION_CODES.N

    @Override
    public void onVisibilityAggregated(boolean isVisible) {
        super.onVisibilityAggregated(isVisible);
        if (isVisible) //onresume() called
        else // onPause() called
    }
    

    you can read source code of ProgressBar to get idea.

提交回复
热议问题