I am new to Xojo/Android, so apologies if this is obvious or covered already.
How do I make my Android app instance persistent? I.E., can I stop the OS from killing my app? This topic covered extensively on developer.android.com , but I couldn’t find any mention in the Xojo docs.
If the only option is to write everything to a filel/db, can you direct me to where that is in the Xojo docs, please?
Thanks!
MarkusR
(MarkusR)
August 28, 2025, 8:24pm
2
usually a android app goto pause if it is not in front and awake and continue if it get in focus.
in past there was an option to prevent sleep mode, the phone stay awake.
disadvantage was that all apps waste energy and the battery get empty.
background services can be stopped by OS for energy savings but user can allow them manually to run permanent.
what i experienced in past was that android close and open a screen if the device was rotated,
means the input was lost.
the quick-and-dirty workaround was do make the app only landscape or portrait to disable the turn.
the worst at android is if you remove/uninstall a app everything of this folder get lost.
guess what happens when a developer can make a persistent not closable foreground app.
Liam_Saw
(Liam Saw)
August 28, 2025, 10:47pm
3
Using the app identifier you can make the screen_main a foreground service which adds a banner in the status bar notification menu. Currently you need to write the code in a AAR library and call it (as it isn’t built into Xojo yet). This is probably a bit advanced if youre just starting out.
Example
I’ve create an MDM (Mobile Device Management) App. It allows you to provision an Android device and control it. I’ll add a desktop app to generate the QR for provisioning. I’ll also add some screenshots of the current system. I have had to remove proprietary code so it is a little bare in its functionality back to the server. I have only included the local capabilities. This project can be easily expanded. It is able to run in the foreground and keep a consistent TCP connection to a server. In m…
Added a QR generator desktop app so you can load the app as an admin app via the welcome screen. Select the APK and it’ll generate the QR code. Tap the welcome screen on an Android device 6 times and it’ll open the camera. Scan the QR code and it’ll load the app as an Admin. Change the URL to where the package is located.
**Striped down version of a webapp
[image]
MarkusR
(MarkusR)
August 29, 2025, 11:22am
4
maybe you missed a error handling in any method, the app ends.
https://documentation.xojo.com/api/mobile/mobileapplication.html#mobileapplication-unhandledexception
or you block the main thread with a method that needs a very long execution time, the os not like that.
i like to use System.DebugLog(CurrentMethodName) in events or methods to follow what happens.
Thanks guys, appreciate the responses. Sounds like it is non-trivial to use Xojo to make my app persistent ala ‘saved instance state’.
I’ve moved to plan B - write a small text file with my non-static data - the app reads it in when it starts and I’m back in business.
Thanks again for weighing in.
1 Like