如何重启Android系统中的装载器?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1331个文字,预计阅读时间需要6分钟。
在使用initLoader()方法时,若指定的ID的加载器存在,则使用该已存在的加载器;否则,会创建一个新的加载器。但有时你可能想丢弃旧数据并重新启动加载器。这时,你可以使用restartLoader()方法。
在使用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; }
LoaderManager.LoaderCallbacks是一个让客户与LoadManager进行交互的回调接口。
本文共计1331个文字,预计阅读时间需要6分钟。
在使用initLoader()方法时,若指定的ID的加载器存在,则使用该已存在的加载器;否则,会创建一个新的加载器。但有时你可能想丢弃旧数据并重新启动加载器。这时,你可以使用restartLoader()方法。
在使用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; }
LoaderManager.LoaderCallbacks是一个让客户与LoadManager进行交互的回调接口。

