Skip to content

Commit

Permalink
Merge pull request #1775 from OneSignal/fix/anrs_on_backgrounding_app
Browse files Browse the repository at this point in the history
Prevent ANRs when backgrounding app
  • Loading branch information
jkasten2 authored May 11, 2023
2 parents 0a313f2 + 56dd55b commit 631fa0f
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ private void handleLostFocus() {
if (focusHandler == null || focusHandler.hasBackgrounded() && !focusHandler.hasCompleted())
return;

OneSignal.getFocusTimeController().appStopped();
focusHandler.startOnLostFocusWorker(FOCUS_LOST_WORKER_TAG, SYNC_AFTER_BG_DELAY_MS, OneSignal.appContext);
new Thread() {
public void run() {
// Run on it's own thread since both these calls do disk I/O
// which could contribute a significant amount to ANRs.
OneSignal.getFocusTimeController().appStopped();
focusHandler.startOnLostFocusWorker(FOCUS_LOST_WORKER_TAG, SYNC_AFTER_BG_DELAY_MS, OneSignal.appContext);
}
}.start();
}

private void handleFocus() {
Expand Down

0 comments on commit 631fa0f

Please sign in to comment.