mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-07-31 04:28:56 +00:00
Fixed java.lang.ClassNotFoundException: Didn't find class "android.window.OnBackInvokedCallback" on Android 8.0
This commit is contained in:
@@ -787,25 +787,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
}
|
||||
}
|
||||
|
||||
static OnBackInvokedCallback backButtonCallback = new OnBackInvokedCallback() {
|
||||
Handler mBackKeyHandler;
|
||||
|
||||
@Override
|
||||
public void onBackInvoked() {
|
||||
if (mBackKeyHandler == null) {
|
||||
mBackKeyHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
onNativeKeyDown(KeyEvent.KEYCODE_BACK);
|
||||
mBackKeyHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNativeKeyUp(KeyEvent.KEYCODE_BACK);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
|
||||
static OnBackInvokedCallback backButtonCallback;
|
||||
static boolean mBackKeyTrapEnabled = false;
|
||||
public static void setBackButtonTrapEnabled(boolean enabled) {
|
||||
|
||||
@@ -819,6 +801,27 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
return;
|
||||
}
|
||||
|
||||
if (backButtonCallback == null) {
|
||||
backButtonCallback = new OnBackInvokedCallback() {
|
||||
Handler mBackKeyHandler;
|
||||
|
||||
@Override
|
||||
public void onBackInvoked() {
|
||||
if (mBackKeyHandler == null) {
|
||||
mBackKeyHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
onNativeKeyDown(KeyEvent.KEYCODE_BACK);
|
||||
mBackKeyHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNativeKeyUp(KeyEvent.KEYCODE_BACK);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
mSingleton.getOnBackInvokedDispatcher().registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, backButtonCallback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user