You need to use an android service if you want to actually do computation in the background. Python-for-android can do this, the relevant documentation is here (old_toolchain). For the new toolchain method see here.
If you just want your app to not be closed completely (so that it doesn't restart entirely with the splash screen etc. every time), you just have to add an on_pause
method to your App class, and it should return True
. You can also do any pre-pause stuff in this method. However, the app doesn't really keep running, it just keeps memory state.
In the latter case, be aware that android can and sometimes will kill apps in a pause state. This is a normal part of the way apps are handled and you can't avoid it, so you should save any important state in your on_pause
method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…