Bug 1437382 - Part 2 - Allow triggering application-background earlier when possible. r?jchen
If onActivitySaveInstanceState is called, this normally happens just before
onActivityStopped, which means we can attempt to use the same logic currently
used for onActivityStopped to determine whether the whole app is going into the
background or we're doing just an internal activity switch.
This allows us to trigger our Gecko onPause/"application-background" handling
*before* e.g. GeckoApp's onSaveInstanceState handling, meaning we still have
time to update the private browsing data held in GeckoApp before it is passed
off to the OS.
MozReview-Commit-ID: 5TZ6uX0gyz1
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoActivityMonitor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoActivityMonitor.java
@@ -27,16 +27,27 @@ public class GeckoActivityMonitor implem
private void updateActivity(final Activity activity) {
if (currentActivity.get() == null) {
((GeckoApplication) activity.getApplication()).onApplicationForeground();
}
currentActivity = new WeakReference<>(activity);
}
+ private void checkAppGoingIntoBackground(final Activity activity) {
+ // For the previous activity, this is called after onStart/onResume for the
+ // new/resumed activity, so if we're switching activities within our app,
+ // currentActivity should already refer to the next activity at this point.
+ // If it doesn't, it means we've been backgrounded.
+ if (currentActivity.get() == activity) {
+ currentActivity.clear();
+ ((GeckoApplication) activity.getApplication()).onApplicationBackground();
+ }
+ }
+
public Activity getCurrentActivity() {
return currentActivity.get();
}
public synchronized void initialize(final GeckoApplication app) {
app.registerActivityLifecycleCallbacks(this);
}
@@ -52,26 +63,20 @@ public class GeckoActivityMonitor implem
public void onActivityResumed(Activity activity) {
updateActivity(activity);
}
@Override
public void onActivityPaused(Activity activity) { }
@Override
- public void onActivityStopped(Activity activity) {
- // onStop for the previous activity is called after onStart/onResume for
- // the new/resumed activity, so if we're switching activities within our
- // app, currentActivity should already refer to the next activity at
- // this point.
- // If it doesn't, it means we've been backgrounded.
- if (currentActivity.get() == activity) {
- currentActivity.clear();
- ((GeckoApplication) activity.getApplication()).onApplicationBackground();
- }
+ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
+ checkAppGoingIntoBackground(activity);
}
@Override
- public void onActivitySaveInstanceState(Activity activity, Bundle outState) { }
+ public void onActivityStopped(Activity activity) {
+ checkAppGoingIntoBackground(activity);
+ }
@Override
public void onActivityDestroyed(Activity activity) { }
}