Skip to content

Commit 36f4936

Browse files
authored
Create a _global_listener to prevent garbage collection
1 parent 1ee731c commit 36f4936

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • pythonforandroid/recipes/android/src/android

pythonforandroid/recipes/android/src/android/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def onApplyWindowInsets(self, view, insets):
6666
traceback.print_exc()
6767
return insets
6868

69+
_global_listener: InsetsListener
6970

7071
@run_on_ui_thread
7172
def update_system_ui(
@@ -141,10 +142,10 @@ def update_system_ui(
141142
decor_view.setSystemUiVisibility(visibility_flags)
142143

143144
if Build_VERSION.SDK_INT >= 35:
144-
listener = InsetsListener(status_color_int, navigation_color_int, pad_status, pad_nav)
145145
# I don't know why but sometimes pyjnius failed to find invoke, maybe due to garbage collection and so I made a reference
146-
mActivity._system_ui_listener = listener
147-
decor_view.setOnApplyWindowInsetsListener(listener)
146+
global _global_listener
147+
_global_listener = InsetsListener(status_color_int, navigation_color_int, pad_status, pad_nav)
148+
decor_view.setOnApplyWindowInsetsListener(_global_listener)
148149
decor_view.requestApplyInsets()
149150
else:
150151
window.setStatusBarColor(status_color_int)

0 commit comments

Comments
 (0)