Clear recent access list when fragment is paused.

When the fragment is resumed, the recent access list will be reloaded.
Clearing the list ahead of time results in a nicer animation and matches
the animtion when the fragment is first open.

Bug: 191503437
Test: manual
Change-Id: I91d01057acc601e6b2a40401f8bd69c5f5aa3579
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 8f9787b..13300c9 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -63,6 +63,7 @@
 
     private LocationSwitchBarController mSwitchBarController;
     private LocationEnabler mLocationEnabler;
+    private RecentLocationAccessPreferenceController mController;
 
     @Override
     public int getMetricsCategory() {
@@ -86,13 +87,22 @@
         super.onAttach(context);
 
         use(AppLocationPermissionPreferenceController.class).init(this);
-        use(RecentLocationAccessPreferenceController.class).init(this);
+        mController = use(RecentLocationAccessPreferenceController.class);
+        mController.init(this);
         use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this);
         use(LocationForWorkPreferenceController.class).init(this);
         use(LocationSettingsFooterPreferenceController.class).init(this);
     }
 
     @Override
+    public void onPause() {
+        super.onPause();
+        if (mController != null) {
+            mController.clearPreferenceList();
+        }
+    }
+
+    @Override
     protected int getPreferenceScreenResId() {
         return R.xml.location_settings;
     }
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index ba660ee..ea3704c 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -127,6 +127,15 @@
     }
 
     /**
+     * Clears the list of apps which recently accessed location from the screen.
+     */
+    public void clearPreferenceList() {
+        if (mCategoryRecentLocationRequests != null) {
+            mCategoryRecentLocationRequests.removeAll();
+        }
+    }
+
+    /**
      * Initialize {@link ProfileSelectFragment.ProfileType} of the controller
      *
      * @param type {@link ProfileSelectFragment.ProfileType} of the controller.