runnerup icon indicating copy to clipboard operation
runnerup copied to clipboard

[Bug] Exit the App with Android "back" Button

Open nottheend opened this issue 1 year ago • 10 comments

Having the App open and pressing the Android back Button/functionality doesn't work on my Android 13 decice. A toast message appears "Press Back again to exit" pressing the Back-Button one time.. After that only this toast message appears again and again continuing to press back.

Device: Google Pixel Android Version: 13

nottheend avatar Apr 25 '23 03:04 nottheend

Back must be pressed within 3s, otherwise there is a new toast.

gerhardol avatar Apr 27 '23 21:04 gerhardol

Exiting the app with triggering the back button multiple times within 3 seconds doesn't work for me. I get the toast that I have to trigger it again though.

In general the back button works in other parts of the app

nottheend avatar Jun 01 '23 07:06 nottheend

I have the same problem with my Pixel 6 running Android 14. From Android 13 the onBackPressed method (that this app uses to exit) is deprecated and should not be used. See https://developer.android.com/reference/android/app/Activity#onBackPressed(). Perhaps this causes the problem?

roberi avatar Dec 26 '23 22:12 roberi

That seem to explain it. My OnePlus with Android 13 phone should get the Android 14 update within two months, hopefully deviating less than A13 so I can investigate better.

gerhardol avatar Dec 26 '23 23:12 gerhardol

I have made some tests and using androidx.activity.OnBackPressedCallback (and OnBackInvokedCallback in SettingsActivity) seems to fix the issue. I can make a PR I you want to have a look/try.

roberi avatar Jan 01 '24 19:01 roberi

I have made some tests and using androidx.activity.OnBackPressedCallback (and OnBackInvokedCallback in SettingsActivity) seems to fix the issue. I can make a PR I you want to have a look/try.

yes please

gerhardol avatar Jan 01 '24 19:01 gerhardol

Unfortunately, using OnBackPressedCallback/OnBackInvokedCallback did not solve the issue after all.

During my tests, I had enabled the Predictive back animations feature on my device (Settings > System > Developer options). When this setting is disabled, the problem is still there.

A quick and simple fix, perhaps, would be to replace

super.onBackPressed(); // finish activity

with

finish(); // finish activity

in SettingsActivity.onBackPressed() (line 416)?

The root cause seems to be TabActivity that MainLayout extends. If StartActivity is declared as the main activity (in Manifest.xml) instead of MainLayout, exiting from StartActivity works as intended.

I think the "correct" fix would be to replace TabActivity with AppCompatActivity as suggested in #648.

roberi avatar Jan 07 '24 16:01 roberi

Thanks for the info. It often is more difficult then it seems.

I think the "correct" fix would be to replace TabActivity with AppCompatActivity as suggested in #648.

Yes, that requires rewriting the activities to fragments so not trivial (maybe for settings too, that should be easier though).

gerhardol avatar Jan 07 '24 19:01 gerhardol

This seems to be handled in #1176

gerhardol avatar Mar 17 '24 14:03 gerhardol