Problem with kivy on Android : Black screen on resume

126 views
Skip to first unread message

Elby

unread,
Jun 29, 2020, 3:54:16 AM6/29/20
to Kivy users support
Hi,

I'm trying to make my first Android application with Kivy.
It's almost working.
I have no problem launching my application on android.
It seems to work fine, except that when Android resume the application, after switching between application or just turn the tablet on/off, I get a black screen.

I can reproduce this behavior with a very simple application:

main.py:
import kivy
kivy.require('1.10.1')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

try:
    from android.permissions import request_permissions, Permission
    request_permissions([Permission.READ_EXTERNAL_STORAGE])
    request_permissions([Permission.WRITE_EXTERNAL_STORAGE])
except:
    pass


class ABugLayout(BoxLayout):
    pass


class ABugApp(App):

    def build(self):
        root =  ABugLayout()
        return root

    def on_pause(self, *args, **kwds):
        return True

if __name__ == '__main__':
    app = ABugApp()
    app.run()

abug.kv:
#: kivy 1.10.1

<ABugLayout>:
    orientation: "vertical"
    Label :
        text : "Just a bug"
        size_hint: None, None
        size : self.texture_size

    Image:
        source: "./icons/test.png"

I've build my application on linux with the following configuration:
  • Ubuntu 20.04 LTS
  • Buildozer 1.2.0
  • Python 3.8.1
  • Kivy 1.11.1
I have a very simple buildozer.spec file with default configuration.
I've tested this on an android Samsung Galaxy Tab A (Android 9) and on a One Plus 7 phone (Android 10).

Is there anything to configure to prevent that black screen on resume ?

Regards,

Elby


It seems I'm

Robert Flatt

unread,
Jun 29, 2020, 12:49:40 PM6/29/20
to Kivy users support
Try    on_pause(self)     without the other two arguments.

Elby

unread,
Jun 30, 2020, 9:10:09 AM6/30/20
to Kivy users support
I've tried that modification but it doesn't change anything.

I've also noted that if I drag down the notification bar, my application become visible again and works normally.

Is there something to setup anywhere to get visible without having to drag the notification bar?

Robert Flatt

unread,
Jun 30, 2020, 1:13:32 PM6/30/20
to Kivy users support
I have not seen anything like this in a long time, I don't know why it is occuring.
My build environment is the same as yours.

The static calls to request_permissions are unusual, but I don't know why they would break anything.

Do you see the same issue with Hello World?

K leo

unread,
Jun 30, 2020, 4:37:13 PM6/30/20
to Kivy users support
How about combining on_pause() and on_resume()?  But I would first use some print statements in the two callback functions to see if they are indeed invoked.  From the menu:

Event handler called when your application is resuming from the Pause mode.

Warning

When resuming, the OpenGL Context might have been damaged / freed. This is where you can reconstruct some of your OpenGL state e.g. FBO content.

Robert Flatt

unread,
Jun 30, 2020, 5:20:42 PM6/30/20
to Kivy users support
How about combining on_pause() and on_resume()?

When resuming, the OpenGL Context might have been damaged / freed.
Yes that is what it says. But why does nobody else see this?

Can you run Hello World? 

Robert Flatt

unread,
Jun 30, 2020, 8:20:24 PM6/30/20
to Kivy users support
I tried it, I can replicate using that static call to request_permissions().

This usage is probably ambiguous.
request_permissions() opens a dialog (once per install), so calling before the UI exists has unknown meaning.
Doing that on_resume() doubly so ;)

Call request_permissions() from on_start() .
request_permissions() is asynchronous so if you use that permission immediately the usage should be inside a callback.
Also you need to test if the user says 'Deny'.
Finally check the Android docuumentation, I think you will find WRITE implies READ, so there is only one permission to request needed.

    def on_start(self):
        request_permissions
([Permission.WRITE_EXTERNAL_STORAGE])
Reply all
Reply to author
Forward
0 new messages