on_pause() not called on Android

168 views
Skip to first unread message

Der Achim

unread,
Mar 6, 2017, 3:58:40 PM3/6/17
to Kivy users support
When hitting the menu button on my android device, my app's on_pause() is not called, but then on_stop() is. Why is this?

Here is an extract from the program with the relevant functions:


class BeadzDesignerApp(App):        # loads 'beadzdesigner.kv'
    def __init__(self, **kwargs):
        super(BeadzDesignerApp, self).__init__(**kwargs)
       
    def on_start(self):
        Logger.info("BeadzDesignerApp: on_start")
        return True

    def on_stop(self):
        Logger.info("BeadzDesignerApp: on_stop")
   
    def on_pause(self, *args):
        Logger.info("on_pause: o.k.")
        return True




And here is the filtered logcat:


I/python  ( 9537): Starting audio thread
I/python  ( 9537): presplash-fit is null
I/python  ( 9537): presplash (fit=null) mx=3,983402,my=2,240664
I/python  ( 9537): Initialize Python for Android
I/python  ( 9537): ['/data/data/org.achim.beadzdesigner/files/lib/python2.7/site-packages', '/data/data/org.achim.beadzdesigner/files/lib/site-python']
I/python  ( 9537): Android path ['/data/data/org.achim.beadzdesigner/files/lib/python27.zip', '/data/data/org.achim.beadzdesigner/files/lib/python2.7', '/data/data/org.achim.beadzdesigner/files/lib/python2.7/lib-dynload', '/data/data/org.achim.beadzdesigner/files/lib/python2.7/site-packages', '/data/data/org.achim.beadzdesigner/files', '/data/data/org.achim.beadzdesigner/files/lib/python2.7/site-packages/PIL', '/data/data/org.achim.beadzdesigner/files/_applibs']
I/python  ( 9537): Android kivy bootstrap done. __name__ is __main__
I/python  ( 9537): Run user program, change dir and execute main.py
I/python  ( 9537): [INFO              ] [Logger      ] Record log in /data/data/org.achim.beadzdesigner/files/.kivy/logs/kivy_17-03-06_1.txt
I/python  ( 9537): [INFO              ] [Kivy        ] v1.9.1
I/python  ( 9537): [INFO              ] [Python      ] v2.7.2 (default, Mar  4 2017, 12:02:45)
[... stuff deleted ...]
I/python  ( 9537): [INFO              ] [Android     ] create joystick <16>
[... here, the app is ready..]
[... now, I hit the menu button: ...]

I/python  ( 9537): [INFO              ] [Android     ] Must go into sleep mode, check the app
I/python  ( 9537): [INFO              ] [Android     ] App doesn't support pause mode, stop.
I/python  ( 9537): [INFO              ] [Base        ] Leaving application in progress...
I/python  ( 9537): [INFO              ] [BeadzDesignerApp] on_stop
I/python  ( 9537): Python for android ended.

Why is it calling on_start() and on_stop() but does not find on_pause()??

Many thanks,
Achim

Oon-Ee Ng

unread,
Mar 6, 2017, 8:47:52 PM3/6/17
to kivy-...@googlegroups.com
You have 'App doesn't support pause mode', which is odd (try removing *args, shouldn't make a diff, but I don't think there's args there anyway). You said you press the menu button, what does that do in your app?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Der Achim

unread,
Mar 7, 2017, 1:33:28 AM3/7/17
to Kivy users support
I tried on_pause() without the "*arg" argument, the behaviour is the same.

I press the middle button on my mobile, maybe I am wrong in calling it 'menu button'. It is not the left one (which opens the kivy inspector) and not the right one, which does an escape action and stops the app.
With the middle button the screen goes blank immediately and then the main screen of the phone is displayed again. Looks almost like a crash.

Der Achim

unread,
Mar 7, 2017, 3:42:58 PM3/7/17
to Kivy users support
Must have to do something with my app. When I comment out nearly everything, on_pause works. Ok, I am going on a hunt...

Der Achim

unread,
Mar 7, 2017, 4:36:51 PM3/7/17
to Kivy users support
#*"!!#*$%! It is that old App()-thing again!

I had the follwing code somewhere inside a constructor: data_dir = App().user_data_dir
That should be o.k. since the garbage collector will delete the temporarily created App-object, right?
NOOO! Somehow this overrides the 'real' App-object - the one that is derived from App and does everything.
Then, when android queries the on_pause() function it does not get the one I defined which returns 'true'. It gets the default one which returns 'false'. And that's the end of the app...

EVERYBODY (and me in the first place) should read the excellent analysis of marystern here:
https://github.com/kivy/kivy/issues/3584

So, the correct code for getting the user directory is:
data_dir = App.get_running_app().user_data_dir

And beware even more:

On my Samsung I get the following directories:
App().user_data_dir      -->                     /sdcard/
App.get_running_app().user_data_dir --> /sdcard/beadzdesigner

Another indication that App().something is very very wrong.

Oon-Ee Ng

unread,
Mar 8, 2017, 8:16:32 PM3/8/17
to kivy-...@googlegroups.com
That's basic python though. Calling App() creates a new object, and kivy only allows for one to be around at any time. All examples use App.get_running_app(), too.

--

Der Achim

unread,
Mar 9, 2017, 4:24:01 AM3/9/17
to Kivy users support
So it is like "Thou shalt have no other apps before me"...

ZenCODE

unread,
Mar 9, 2017, 7:15:46 AM3/9/17
to Kivy users support
Well, you can have another App. But that would then be another app, with a totally independent set of values, variables and memory allocations, all inaccessible to this App as operating systems isolate processes. So, it's kinda logical really...:-)
Reply all
Reply to author
Forward
0 new messages