Closed hottwaj closed 8 years ago
I have the same problem when back button is pressed (escape). I fix the issue with the following code:
def on_keyboard(self, window, key, scancode=None, codepoint=None, modifier=None):
if platform == 'android' and key == 27:
from jnius import autoclass, cast
PythonActivity = autoclass('org.kivy.android.PythonActivity')
activity = PythonActivity.mActivity
Intent = autoclass('android.content.Intent')
intent = Intent()
intent.setAction(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
currentActivity = cast('android.app.Activity', activity)
currentActivity.startActivity(intent)
return True
It seems that interaction between android.pyx, pyjnius and app pause mode can cause deadlock when going into pause mode or when resuming from pause mode. I am using the pygame bootstrap.
A few logs and things below to show what's going on
Here's the typical sequence - first I press the home button and the app should pause.
Note that after the "app paused" message, the Java interface of pyjnius receives a call which it tries to push to Python. The log message is from line 15 of NativeInvocationHandler.java of pyjnius
The above happens before I try to resume my app.
Once I try to resume, I get a black screen and nothing happens. I have logging setup on the pygame bootstrap and I can see that the app's onResume() method in PythonActivity.java is never called.
I get the following log output
Normally I can only trigger this outcome if I press the "home" button. If I open the "apps task switcher" menu and then immediately switch back to my app, resume is handled correctly.
I believe this is a deadlock issue because occasionally an ANR crash occurs (not always though - probably because the call to NativeInvocationHandler.java does not always happen before app pause, but sometimes happens on resume).
Below is the ANR stack trace which sometimes occurs when the app is resumed and has been sat at black screen for a while - the crash occurs because pyjnius' NativeInvocationHandler.java can't get hold of a lock on a python thread (GIL maybe?)
It seems like either pyjnius or PythonActivity.java need to somehow "know" that the app is paused in order to somehow prevent this situation?