'How to reassign listener in onAttach of a fragment when parent is also a fragment instead of Activity?

I know that in order to reassign listener when a fragment is recreated and fragment's parent is an activity, we assign listener instance in following way:


override fun onAttach(context: Context) {
    if(context is MyListener){
       this.listener = context
    }
}

As far as I know this context always refers to an activity.

How would I achieve the same in case parent of frament is also a fragment



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source