Do not start suggestion loader if host isn't attached.

Change-Id: I1ab1de8f0bea6c66d8415e06aedcc7cbc6baf89c
Fixes: 68759380
Test: robotests
This commit is contained in:
Fan Zhang
2017-11-01 10:09:04 -07:00
parent f60c99af53
commit 6d7aa4e951
3 changed files with 28 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.dashboard;
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -95,6 +96,14 @@ public class DashboardSummary extends InstrumentedFragment
}
}
@Override
public LoaderManager getLoaderManager() {
if (!isAdded()) {
return null;
}
return super.getLoaderManager();
}
@Override
public void onCreate(Bundle savedInstanceState) {
long startTime = System.currentTimeMillis();

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Loader;
import android.os.Bundle;
import android.service.settings.suggestions.Suggestion;
import android.support.annotation.Nullable;
import android.util.Log;
import com.android.settings.overlay.FeatureFactory;
@@ -44,8 +45,10 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
void onSuggestionReady(List<Suggestion> data);
/**
* Returns {@link LoaderManager} associated with the host.
* Returns {@link LoaderManager} associated with the host. If host is not attached to
* activity then return null.
*/
@Nullable
LoaderManager getLoaderManager();
}
@@ -82,8 +85,11 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
@Override
public void onServiceConnected() {
mHost.getLoaderManager().restartLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS,
null /* args */, this /* callback */);
final LoaderManager loaderManager = mHost.getLoaderManager();
if (loaderManager != null) {
loaderManager.restartLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS,
null /* args */, this /* callback */);
}
}
@Override