在使用initLoader()方法时,如果指定ID的装载器存在,就使用这个既存的装载器,否则会创建一个新的。但是有些时候你会想要废弃旧的数据并重启装载器。
你可以使用restartLoader()方法来废弃旧的数据。例如,SearchView.OnQueryTextListener的实现就会在用户查询改变时重启装载器。装载器需要重启以便能够使用修正后的搜索过滤器来进行新的查询,如:
public boolean onQueryTextChanged(String newText) {
// Called when the action bar search text has changed. Update
// the search filter, and restart the loader to do a new query
// with this filter.
mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
getLoaderManager().restartLoader(0, null, this);
return true;
}