From 5e9be8c7357d95398f91ab01d60d8b9c818fd748 Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Tue, 5 Nov 2024 14:42:33 +0000 Subject: [PATCH] Fix leaking form session when viewing submission --- .../ViewOnlyFormHierarchyActivity.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/formhierarchy/ViewOnlyFormHierarchyActivity.kt b/collect_app/src/main/java/org/odk/collect/android/formhierarchy/ViewOnlyFormHierarchyActivity.kt index 0c0a498c3d9..d1647b15460 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formhierarchy/ViewOnlyFormHierarchyActivity.kt +++ b/collect_app/src/main/java/org/odk/collect/android/formhierarchy/ViewOnlyFormHierarchyActivity.kt @@ -3,6 +3,7 @@ package org.odk.collect.android.formhierarchy import android.os.Bundle import android.view.View import android.widget.Button +import androidx.activity.OnBackPressedCallback import org.javarosa.core.model.FormIndex import org.odk.collect.android.R import org.odk.collect.android.javarosawrapper.FormController @@ -14,7 +15,16 @@ import org.odk.collect.android.javarosawrapper.FormController class ViewOnlyFormHierarchyActivity : FormHierarchyActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + onBackPressedCallback.remove() + onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + setResult(RESULT_OK) + finish() + val sessionId = intent.getStringExtra(EXTRA_SESSION_ID)!! + formSessionRepository.clear(sessionId) + } + }) } /** @@ -23,10 +33,7 @@ class ViewOnlyFormHierarchyActivity : FormHierarchyActivity() { */ public override fun configureButtons(formController: FormController) { val exitButton = findViewById