-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix background crash focus #11789
base: dev
Are you sure you want to change the base?
Fix background crash focus #11789
Conversation
Quality Gate passedIssues Measures |
override fun onStart(owner: LifecycleOwner) { | ||
editor.putBoolean(KEY_IS_IN_BACKGROUND, false).commit() | ||
Log.d(TAG, "App moved to foreground") | ||
} | ||
|
||
override fun onPause(owner: LifecycleOwner) { | ||
editor.putBoolean(KEY_IS_IN_BACKGROUND, true).commit() | ||
Log.d(TAG, "App moved to background") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you override these functions directly in MainActivity
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can, i just missed that AppCompatActivity has these methods to overwrite. Unfortunately it does not seem like it fixes the occasionally wrong behavior i mentioned, probably something related to ACRA but I am unsure how to fix it.
Can we add a button to the |
I don't know how necessary it is to have a dedicated button for that, but if you want to reproduce it, you can do it very easily using something like:
You could create a new button like the |
I couldn’t reproduce it by either inserting that into MainActivity nor Player; do you have a commit with the exact position where you added that? |
I never commited it because I don't wanted to mess with the git history, maybe I am missunderstanding though what you can not reproduce? |
I cannot reproduce the error screen popping up and taking focus when NewPipe is in the background. If you want, you can commit the example on a fresh branch and just link the branch or the commit directly. |
Maybe it's something device specific? I can provide a commit that I used to test but it really just boils down to adding the code I mentioned into the first line after |
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, false).apply(); | ||
Log.d(TAG, "App moved to foreground"); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, true).apply(); | ||
Log.d(TAG, "App moved to background"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an app of mine I used a static field instead of the preferences, since there is only going to be one MainActivity alive at a time anyway: https://github.com/Stypox/dicio-android/blob/master/app/src/main/kotlin/org/stypox/dicio/MainActivity.kt#L178
Maybe it would be better if you switched to a static field now that I think of it, so you can make the code simpler and not rely on shared preferences (which do disk I/O every time).
Also, put the Log.d behind an if (DEBUG) { ... }
Yes I think from Android 13 the background intents are blocked anyway |
Ah, so I need to test on an older Android version, I see. |
What is it?
Description of the changes in your PR
This PR addresses the issue of NewPipe stealing focus to report an error even while it is in the background.
To check if the app has been in the background a monitoring class (that could also be used for different purposes) and a shared preference have been introduced to ensure that the state is correctly remembered and can then handle the reporting accordingly e.g. only show a notification if the crash happened while in foreground and show a not.
This was tested via delayed test crashes:
Occasionally i have seen this misbehave seemingly when another crash occurred before with a different foreground/background state. Unfortunately i have not found a fix for this, if somebody wants to take a look or can reproduce it I would be grateful. I am also open to completely different approaches since this approach is of course not optimal.
Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.
Due diligence