推出例外:
。 发生了什么事??。 我可以使用与LoaderCallbacks相同的LoaderID吗?
public class DetailActivity extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<Cursor> {
private static final int FORECAST_LOADER = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
.................
// Init Loader data from provider
getSupportLoaderManager().initLoader(FORECAST_LOADER, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Long routeId = 1234;
Uri routesUri = RouteContract.RouteEntry.buildRouteUri(routeId);
return new CursorLoader(this,
routesUri,
RouteContract.RouteEntry.FORECAST_COLUMNS,
null,
null,
null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
..............(Run OK)
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
............. (Run OK)
}
答案 0 :(得分:0)
我找到了简单的解决方案:
旋转设备后(savedInstanceState!= null): restartLoader
if (savedInstanceState == null) {
getSupportLoaderManager().initLoader(FORECAST_LOADER, null, this);
} else {
getSupportLoaderManager().restartLoader(FORECAST_LOADER, null, this);
}