现在的位置: 首页 > 综合 > 正文

LoaderCallbacks 自动重新调用

2018年04月13日 ⁄ 综合 ⁄ 共 691字 ⁄ 字号 评论关闭

不知道大家有没有用LoaderCallbacks<RESTLoader.RESTResponse>这个进行网络请求,今天碰到一个BUG,就是只要在一个页面中调整完时间,以前走过的网络请求会自动重新走一次,仔细查资料发现原因在这儿:

Introduced in Android 3.0, loaders make it easy to asynchronously load data in an activity or fragment. Loaders have these characteristics:

  • They are available to every Activity and Fragment.
  • They provide asynchronous loading of data.
  • They monitor the source of their data and deliver new results when the content changes.
  • They automatically reconnect to the last loader's cursor when being recreated after a configuration change. Thus, they don't need to re-query their data.

http://developer.android.com/guide/components/loaders.html

就是随着环境变量会重新链接。所有每次在请求完毕之后执行loaderManager.destroyLoader(loader.getId());

其实这个框架整体使用起来还是比较舒服的,但是真正不了解之后会发现有好多未知的问题!

抱歉!评论已关闭.