Can I save an Android app in the background?

Currently, I have programmed a regular Andorid application (no service). It contains a timer for periodic checks. To avoid problems with the service and the connection between the Service and the Application, I ask myself if there is a way to save an application that is no longer in the foreground. Currently, when I โ€œcloseโ€ the application, it is still alive until the Android OS decides to kill it. Is there any way to avoid this killing - for example, by a specific command in "onDestroy" or a specific App flag? My application is quite complicated, and I do not want to implement a Service like this, especially communication / binding - it increases complexity. Is there a "easy way", or am I really forced to use Service + App? Maybe there is a trick to register an application for sth. A feature that has a side effect is that the Android OS does not kill it when it is in the background.

Edit for a better understanding: itโ€™s normal that the GUI can go into the background (disappear) when the user wants it, so my question is not to allow the graphical interface of my application to be constantly in the foreground. All I want is that the timer remains intact without the need for additional service.

Thanks everyone for the ideas in advance!

+4
source share
3 answers

Android is very unpredictable in terms of the choice of OS kill and market fragmentation. I would not consider that 100% of something will survive, if it is crucial. However, you can gamble and be quite successful. This will help you:

  • Use very good "best practices" to keep the row pool and heap at a minimum, since Android first wants to kill the memory boxes (and because you like what you do).
  • Add a persistent attribute to your application manifest tag.
  • To really help yourself, start or run the service, because they are long processes, very easy (if they are implemented well), and Android hopes to kill them at last.
  • Provide your service priority by running it as a front-end service.

Performing these steps will increase the likelihood that Android will not kill your application.

+5
source

I do not think there is anything like that. I suggest looking at AlarmManager for periodic tasks - this may mean that you do not need to use the service.

+1
source

Applications available in the background are simply a measure of caching by the Android operating system to avoid having to restart a frequently used application from scratch. If you want to rely on your application running in the background, then this is the right solution. This is not the answer you are looking for, but I donโ€™t know any tricks to stay in the cache, and if they were, I would not recommend them well.

0
source

Source: https://habr.com/ru/post/1399484/


All Articles