I am trying to resolve the onBackPressed() in Activity has been deprecated warning in API33 (Android Studio). Both my compileSdkVersion and targetSdkVersion is 33.
Following the instructions here, I added to the build.gradle implementation:
implementation 'androidx.appcompat:appcompat:1.6.0-alpha04'
(same problem happens with the newer rc01) and imported the callback in the activity (FullScreenBrowser) with
import androidx.activity.OnBackPressedCallback;
Then I added this code to the activity class:
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Back is pressed... Finishing the activity
finish();
}
});
But I get an error:
Cannot resolve method 'getOnBackPressedDispatcher' in 'FullScreenBrowser'.
Maybe this has to do with the lack of support of API33 in AndroidStudio? Or maybe getOnBackInvokedCallback is an option?