How do I make my Android app persistent?

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!

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.

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

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