Application is sent to background while execution

My mobile app is moved to background and it is reset i.e when I pause execution and put the app in focus it shows login page and not the page where it was executing certain behaviour.
Also this happens very randomly, and no error is printed in logs as well. I am trying to scroll in app and then suddenly the app is sent to background.
Below is the code snippet for scrolling where element is the xpath of element:

if direction == 'up':
        self.builtIn.run_keyword("Swipe By Percent", 50, 80, 50, 50, 400)
        element_found = self.builtIn.run_keyword_and_return_status(
            "Element Should Be Visible", element)
        self.builtIn.run_keyword_and_return_status("Log", element_found)
elif direction == 'down':
        self.builtIn.run_keyword("Swipe By Percent", 50, 50, 50, 80, 400)
        element_found = self.builtIn.run_keyword_and_return_status(
            "Element Should Be Visible", element)
        self.builtIn.run_keyword_and_return_status("Log", element_found)

Here is my best guess:
Starting with Android 12 (I think), there is a new gesture available. If you swipe from the bottom of the screen upwords, the app that is currently on the screen will be sent to background. Although your keyword does not scroll exactly from the bottom, this might happen.
In order to avoid this, I believe you can deactivate these gestures and bring back the 3 buttons on the bottom of the screen. They can be re-activated in Settings: Get around on your Android phone - Android Help

Menus may differ from system to system but you should be able to find that menu.
What You need is to activate 3-button navigation. That will disable gestures and thus will prevent the Swipe from sending the app into the background (hopefully)