Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run the application in background

I am trying to build android app using kivy. How I can hide my app but still keep it running in the background like a deamon?

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'fake')

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        button = Button(text="Exit", size_hint=(None, None))
        button.bind(on_press=exit)
        return button

if __name__ == '__main__':
    MyApp().run()
like image 959
sam Avatar asked Dec 21 '13 13:12

sam


People also ask

What does it mean to run app in background?

In Windows, apps can continue to perform actions even when you are not actively in the app's window. These are commonly called background apps. You can decide which apps will run in the background, and which won't.

What happens if apps run in background?

How Background Apps Affect Your Android Battery. Your Android device can run multiple apps in the background for a few reasons. Most of the time, it won't cause any battery or memory consumption problems. One factor causing your Android device's battery to drain too quickly is when there are too many apps running.


1 Answers

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.

like image 90
inclement Avatar answered Sep 27 '22 17:09

inclement