facing unResolvedReference error when using onBackPressedDispatcher

102 Views Asked by At

enter image description here kotlin version : 1.6.1 implementation "androidx.appcompat:appcompat:1.4.2" // I used 1.6.1 too but no use implementation "androidx.fragment:fragment-ktx:1.5.1" implementation "androidx.activity:activity-ktx:1.5.1"

While taking ctrl reference from the base activity : I encountered similar issue described here Wrong version of androidx.fragment:fragment used

I need to resolve onBackPressed deprecation with onBackpressedDispatcher

1

There are 1 best solutions below

0
sasikumar On

In your fragment you should call like this

requireActivity().onBackPressedDispatcher.addCallback(
  this, // LifecycleOwner
  callback
)

Fore more details refer : OnBackPressedDispatcher