3

I'm trying to customize onBackPress behaviour of JetPack Navigation. Although I found the solution I'm just curious what's going behind the scenes in the following scenario:

Initial state of my activity is

MyActivity extends androidx.appcompat.app.AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getOnBackPressedDispatcher().addCallback(...);  // <--- Method is unresolved
    }
}

How come that after I add the following dependency to build.gradle the getOnBackPressedDispatcher() method is being resolved:

implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'

What's going behind the scenes? Does it have something with the Jetifier? Does it alter the classes based on declared dependencies or something similar?

Michal Vician
  • 2,486
  • 2
  • 28
  • 47
  • did you found any solution? – Rajesh Koshti Aug 24 '23 at 09:22
  • If you mean the solution to resolve the dependency problem, then it is already presented in the question itself (`getOnBackPressedDispatcher()` is being resolved after adding `navigation-fragment` and `navigation-ui` dependencies). – Michal Vician Aug 24 '23 at 12:56

1 Answers1

-1

implementation 'androidx.appcompat:appcompat:1.1.0'

Implement this dependency to its latest version, this will fix the problem.

Biplob Das
  • 2,818
  • 21
  • 13