Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nottheend opened this issue Apr 25, 2023 · 10 comments
Open

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

nottheend opened this issue Apr 25, 2023 · 10 comments

Comments

@nottheend
Copy link

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

@gerhardol
Copy link
Collaborator

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

@nottheend
Copy link
Author

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

@roberi
Copy link
Contributor

roberi commented Dec 26, 2023

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?

@gerhardol
Copy link
Collaborator

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.

@roberi
Copy link
Contributor

roberi commented Jan 1, 2024

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.

@gerhardol
Copy link
Collaborator

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

@roberi
Copy link
Contributor

roberi commented Jan 7, 2024

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.

@gerhardol
Copy link
Collaborator

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
Copy link
Collaborator

This seems to be handled in #1176

@ronenfe
Copy link

ronenfe commented Jul 4, 2024

It doesn't work for me either in my app autovolume. I noticed it on Android 14. I have a foreground service. It works on older version. I opened a bug for Google.
https://issuetracker.google.com/issues/351018037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@gerhardol @ronenfe @roberi @nottheend and others