flet icon indicating copy to clipboard operation
flet copied to clipboard

Android App Crashes on Reopening After Closing with Back Button

Open iforvard opened this issue 11 months ago • 16 comments

Description

After building an Android APK using Flet, the app crashes when reopened after being closed with the back button. The crash does not occur if the app is closed through the system's "Recent Apps" menu.

Steps to Reproduce:

  1. Build an Android APK using flet build apk
  2. Install the APK on an Android device.
  3. Open the app.
  4. Close the app using the back button.
  5. Open the app again.
  6. The app will crash.

Reproducible on devices:

Samsung S21 Ultra (Android 14) Sberbox (TV stick with Android 9)

The official flet app on google play has the same behavior (video):

https://github.com/flet-dev/flet/assets/48457650/d1ff4f6a-60fe-4bde-81aa-980ecc8e16e6

iforvard avatar Mar 03 '24 09:03 iforvard

Flut support for Android is not very good, mainly on Windows. My app import some packages, eg. tinytag, which Android could not recognize and show tinytag was not available

huangxulei avatar Mar 06 '24 06:03 huangxulei

I'm having the same problem. Is there a way to assign commands to the phone's navigation key?

yucel685 avatar Mar 06 '24 11:03 yucel685

Estou tendo o mesmo problema. Existe uma maneira de atribuir comandos à tecla de navegação do telefone?

I also want this, instead of closing the application it returns to the page.

xkayo32 avatar Mar 25 '24 02:03 xkayo32

Same issue with S23

dudusandi avatar Apr 03 '24 06:04 dudusandi

I solved this problem with the route change function using views.I used system exit() with import sys for the back key

yucel685 avatar Apr 04 '24 10:04 yucel685

I'm having the same problem on HUAWEI HarmonyOS.

BrentHuang avatar Apr 22 '24 07:04 BrentHuang

add this in your code:

`def event(e): if e.data=='detach' and page.platform == ft.PagePlatform.ANDROID: os._exit(1)

page.on_app_lifecycle_state_change = event`

amun311 avatar Apr 23 '24 14:04 amun311

Could it be possible to minimize the app as if middle button was pressed instead of exit, so it will open faster the next time?

J-PRS avatar May 06 '24 19:05 J-PRS

Could it be possible to minimize the app as if middle button was pressed instead of exit, so it will open faster the next time?

Ad this to your code `def event(e): if e.data=='detach' and page.platform == ft.PagePlatform.ANDROID: os._exit(1)

page.on_app_lifecycle_state_change = event`

When you press middle button it will minimize and when you press back button app will close. You need flet 0.4.0 at least

amun311 avatar May 06 '24 20:05 amun311

I think minimizing would be better but maybe not possible? I've tried before exit on page.on_view_pop and page.on_window_event == minimize, but it didn't work, your solution works perfectly, thank you! It still crashes when opening very fast after closing but hopefully no user will be doing that too much.

J-PRS avatar May 06 '24 20:05 J-PRS