Is there any way to automatically restart my kivy app if android OS (or user) stopped/killed it?

305 views
Skip to first unread message

nesfree

unread,
Sep 5, 2022, 3:44:15 PM9/5/22
to Kivy users support
Hi,

as my android kivy app takes few seconds (let's say 4s) to start I wonder is there any way I could use existing foreground service that works non-stop to monitor and restart the app if it get stopped/killed by android OS or user?

I am asking this because I would like to avoid waiting 4 seconds every time I need it. It is very annoying :)

I know that there are ways to optimize app itself but even elementary android kivy app takes few secs to start (as it has to bring whole python with itself?).

When the app is paused it starts almost instantly when called, that is why I would like keep it in paused state.

Thanks in advance,

BR    


Robert

unread,
Sep 5, 2022, 7:58:29 PM9/5/22
to Kivy users support
Probably the easiest solution is to either buy a phone with more memory, or remove other tasks from the task list yourself.
Alternatively look in the store to see if there is an app to do this for you.

Certainly there is nothing 'automatic' in p4a.
And if it did it would steal the screen for "4 seconds" which would be the same "annoying" behavior.

Generally this would seem like a security risk if a background activity can start an unrelated foreground activity. It may not be allowed by Android, but I can't decode this https://developer.android.com/guide/components/activities/background-starts

nesfree

unread,
Sep 6, 2022, 6:33:42 AM9/6/22
to Kivy users support
Hi Robert, 

many thanks for answering.

Just few comments on your response:

Certainly there is nothing 'automatic' in p4a.
Maybe I did not understand you here but I did not mean to p4a do something automatically but to I implement in kivy (foreground) service some logic to periodically check whether my kivy app is running/paused/stopped and act accordingly. 

Generally this would seem like a security risk if a background activity can start an unrelated foreground activity.
 Again maybe I did not understand you but if my service is started from my kivy app like:

            from jnius import autoclass
            service = autoclass('org.test.myapp.ServiceMyservice')
            mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
            argument = ''
            service.start(mActivity, argument)

and if clicking on my service's persistent notification resume/start my kivy app aren't they related somehow more than with some 3rd app?

But as you  said: even if  it would be possible  if it would steal the screen for "4 seconds" it would be the same "annoying" behavior.
I hoped to keep/refresh my kivy app in task list but not on screen.

And one potentially naive question: Is it possible to throw/make any GUI widget from service (not main app)?  I suppose not but hope dies last :)

Thanks and best regards

Robert

unread,
Sep 6, 2022, 5:38:51 PM9/6/22
to Kivy users support
The app's service stops when the app does https://github.com/Android-for-Python/Android-for-Python-Users#service-lifetime
 hence I assumed a 3rd part service.

Instantiating widgets in a service? Not to be part of the UI, and even non-ui behavior may not work as it often depend on the event loop.

nesfree

unread,
Sep 6, 2022, 5:49:24 PM9/6/22
to Kivy users support
Hi Robert,

regarding this: 'The app's service stops when the app does https://github.com/Android-for-Python/Android-for-Python-Users#service-lifetime
 hence I assumed a 3rd part service.'

Service (being started by app) does continue work after app itself is stopped, i.e. it is something called 'foreground' service and has persistent notification and does some non-GUI staff (in my case)...

But as you explained it has nothing to do with GUI stuff.

Thanks for your replays!

BR
Reply all
Reply to author
Forward
0 new messages