How to act if the game is closed in a unusual way?

I was testing my app on my android phone, and i haven’t implemented any exit method yet, so i was just killing the app. But i noticed that the final function does not execute in that situation, what is kind of understandable, but I was wondering if there is any callback function like the onStop or onDestroy on the activity life cycle.

How? By opening the “task manager” and swiping/closing the app that way? The app isn’t running if put in the background so there’s no chance for you to get any calls to any final() functions in scripts. What is it you wish to do when the app is closed? Note that you have window.set_listener() that will get a callback when the app is minimized.