From 207905102c4a844d73376f1a3ec5aea2e2dcfdbd Mon Sep 17 00:00:00 2001 From: Ali <97373457+DevNull-IR@users.noreply.github.com> Date: Tue, 17 Feb 2026 10:25:30 +0330 Subject: [PATCH] Implement custom back press behavior(Android 13+) Added custom back press handling to MainActivity for Android 13+. --- .../main/java/mgks/os/swv/MainActivity.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/mgks/os/swv/MainActivity.java b/app/src/main/java/mgks/os/swv/MainActivity.java index 415f03f..d76998f 100755 --- a/app/src/main/java/mgks/os/swv/MainActivity.java +++ b/app/src/main/java/mgks/os/swv/MainActivity.java @@ -67,6 +67,7 @@ import android.widget.LinearLayout; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; @@ -131,6 +132,32 @@ protected void onCreate(Bundle savedInstanceState) { if (SWVContext.ASWP_BLOCK_SCREENSHOTS) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } + + getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (SWVContext.ASWP_EXIT_ON_BACK) { + if (SWVContext.ASWP_EXITDIAL) { + fns.ask_exit(MainActivity.this); + } else { + finish(); + } + return; + } + + if (SWVContext.asw_view.canGoBack()) { + SWVContext.asw_view.goBack(); + } else { + if (SWVContext.ASWP_EXITDIAL) { + fns.ask_exit(MainActivity.this); + } else { + finish(); + } + } + } + }); + + // Enable edge-to-edge display WindowCompat.setDecorFitsSystemWindows(getWindow(), false); @@ -1037,4 +1064,4 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, } } } -} \ No newline at end of file +}