Detect when in the background
Does anyone know if there is a way to detect when a running program (scene) is in the background (e.g. Because the user has pressed the home button)? I tried it with notifications (since I thought it reacts differently when the program scheduling a notification is in the background), but unfortunately all I managed was to crash Pythonista :-(
Sebastian last edited by
Scene.pause()may work. It says in the docs that the function gets called automatically when the home button is pressed while a scene is running.
Nice suggestion! Unfortunately what I'm trying to do is quit the scene when the user presses the home button, but putting a sys.exit() in there doesn't stop the scene. I also tried to use a delay(0,lambda: sys.exit()), but then the scene ends after relaunching Pythonista. Since what I really want to do is allow for the launch of another program using the pythonista:// custom url, I get the error message 'Already running script' :-(
In the end, using the pause, and using notification('',0,'','pythonista://test?action=run') it 'works' because that crashes the app in the background (but that is not the right way to do it)...