Skip to content

Commit d9051b6

Browse files
Call listener more often
1 parent 9b0cebd commit d9051b6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,27 @@ private void configureNetworkMonitoring() {
9797
}
9898

9999
private void configureBackgroundStateListener() {
100-
Application applicationContext = (Application) context.getApplicationContext();
100+
Application application = (Application) context.getApplicationContext();
101101
final AtomicBoolean inBackground = new AtomicBoolean();
102102

103103
// Manually register an ActivityLifecycleCallback. Android's BackgroundDetector only notifies
104104
// when it is certain that the app transitioned from background to foreground. Instead, we
105105
// want to be notified whenever there is a slight chance that this transition happened.
106-
applicationContext.registerActivityLifecycleCallbacks(
106+
application.registerActivityLifecycleCallbacks(
107107
new Application.ActivityLifecycleCallbacks() {
108108
@Override
109-
public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) {}
109+
public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) {
110+
if (inBackground.compareAndSet(true, false)) {
111+
raiseForegroundNotification();
112+
}
113+
}
110114

111115
@Override
112-
public void onActivityStarted(@NonNull Activity activity) {}
116+
public void onActivityStarted(@NonNull Activity activity) {
117+
if (inBackground.compareAndSet(true, false)) {
118+
raiseForegroundNotification();
119+
}
120+
}
113121

114122
@Override
115123
public void onActivityResumed(@NonNull Activity activity) {
@@ -132,7 +140,7 @@ public void onActivitySaveInstanceState(
132140
public void onActivityDestroyed(@NonNull Activity activity) {}
133141
});
134142

135-
applicationContext.registerComponentCallbacks(
143+
application.registerComponentCallbacks(
136144
new ComponentCallbacks2() {
137145
@Override
138146
public void onTrimMemory(int level) {

0 commit comments

Comments
 (0)