Skip to content

Commit

Permalink
Merge pull request #1945 from bugsnag/fix-inForeground
Browse files Browse the repository at this point in the history
Fix in foreground
  • Loading branch information
lemnik authored Nov 20, 2023
2 parents 5ab3559 + 21888ef commit dc934b8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 6.0.0 (2023-11-16)
## 6.0.0 (2023-11-20)

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ internal object ForegroundDetector : ActivityLifecycleCallbacks, Handler.Callbac
mainThreadHandler.sendMessageDelayed(backgroundMessage, BACKGROUND_TIMEOUT_MS)
} else {
notifyListeners { it.onForegroundStatus(false, stoppedTimestamp) }
isInForeground = false
lastExitedForegroundMs = stoppedTimestamp
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ internal class InForegroundScenario(
) : Scenario(config, context, eventMetadata) {

private var triggered = AtomicBoolean(false)
private val mainHandler = Handler(Looper.getMainLooper())

override fun startScenario() {
super.startScenario()
registerActivityLifecycleCallbacks()

// make sure the app goes to the background
mainHandler.post {
(context as Activity).finish()
}
}

override fun onActivityStopped(activity: Activity) {
Handler(Looper.getMainLooper()).post {
mainHandler.post {
// debounce so this can only ever occur once
if (!triggered.getAndSet(true)) {
log("onActivityStopped is finished, calling Bugsnag.notify in the background")
Expand Down
3 changes: 0 additions & 3 deletions features/full_tests/in_foreground.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ Feature: In foreground field populates correctly
Background:
Given I clear all persistent data

# TODO: Skipped pending PLAT-10634
@skip
Scenario: Test handled exception in background
When I run "InForegroundScenario"
And I send the app to the background for 5 seconds
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
# PLAT-9155 Flaky: the event "app.inForeground" is false
Expand Down

0 comments on commit dc934b8

Please sign in to comment.