android: Replace deprecated onBackPressed() and enable predictive back gestures

Doesn't really make a difference it seems.
This commit is contained in:
Tobias Brunner 2025-02-05 16:13:13 +01:00
parent 9a92088bb4
commit 26eef1f095
2 changed files with 12 additions and 7 deletions

View File

@ -37,6 +37,7 @@
android:label="@string/app_name"
android:theme="@style/ApplicationTheme"
android:networkSecurityConfig="@xml/network_security_config"
android:enableOnBackInvokedCallback="true"
android:allowBackup="false" >
<activity
android:name=".ui.MainActivity"

View File

@ -22,6 +22,7 @@ import android.view.MenuItem;
import org.strongswan.android.data.VpnProfileDataSource;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@ -40,6 +41,16 @@ public class SelectedApplicationsActivity extends AppCompatActivity
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true)
{
@Override
public void handleOnBackPressed()
{
prepareResult();
finish();
}
});
FragmentManager fm = getSupportFragmentManager();
mApps = (SelectedApplicationsListFragment)fm.findFragmentByTag(LIST_TAG);
if (mApps == null)
@ -62,13 +73,6 @@ public class SelectedApplicationsActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed()
{
prepareResult();
super.onBackPressed();
}
private void prepareResult()
{
Intent data = new Intent();