[Settings] Avoid from crash UI when querying data usage

Screen update been requested while querying data usage and response not
yet available.
This change tried to avoid from updating the UI in this case.

Bug: 210664126
Test: local
Change-Id: Id055fbd441936a9842b4acc978a894a855165bb7
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index dc945f1..4ee6530 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -48,6 +48,7 @@
 import android.widget.Spinner;
 
 import androidx.annotation.VisibleForTesting;
+import androidx.lifecycle.Lifecycle;
 import androidx.loader.app.LoaderManager.LoaderCallbacks;
 import androidx.loader.content.Loader;
 import androidx.preference.Preference;
@@ -500,6 +501,17 @@
                         + cycle.end + "]");
             }
 
+            // Avoid from updating UI after #onStop.
+            if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
+                return;
+            }
+
+            // Avoid from updating UI when async query still on-going.
+            // This could happen when a request from #onMobileDataEnabledChange.
+            if (mCycleData == null) {
+                return;
+            }
+
             // update chart to show selected cycle, and update detail data
             // to match updated sweep bounds.
             mChart.setNetworkCycleData(mCycleData.get(position));