上一篇主要理了下LoaderCallback, 其中看到LoaderManager在initLoader之后自動調用了Loader的startLoading方法; 這一篇繼續(xù)理Loader !最后我們就可以把Loader執(zhí)行過程的整個生命周期畫出來了。
先看結構吧,Loader簡單多了。
該類源碼查看:http://www.oschina.net/code/explore/android-4.0.1/core/java/android/content/Loader.java
首先是startLoading 方法
public final void startLoading() { mStarted = true; mReset = false; mAbandoned = false; onStartLoading(); } /*** * Subclasses must implement this to take care of loading their data, * as per {@link #startLoading()}. This is not called by clients directly, * but as a result of a call to {@link #startLoading()}. */ protected void onStartLoading() { }
看到?jīng)],設置了幾個狀態(tài), 然后調用onStartLoading方法就結束了, 而onStartLoading方法又是個空方法.. 好了,圓滿結束!....
尼瑪, 難怪我的loadInBackground方法總是不被調用! 坑爹啊! 那怎么讓你自己Loader的loadInBackground正常被調用呢? 只能重寫onStartLoading方法唄!
看看官方的示例(http://developer.android.com/intl/zh-CN/reference/android/content/AsyncTaskLoader.html):
/** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { if (mApps != null) { // If we currently have a result available, deliver it // immediately. deliverResult(mApps); } // Start watching for changes in the app data. if (mPackageObserver == null) { mPackageObserver = new PackageIntentReceiver(this); } // Has something interesting in the configuration changed since we // last built the app list? boolean configChange = mLastConfig.applyNewConfig(getContext().getResources()); if (takeContentChanged() || mApps == null || configChange) { // If the data has changed since the last time it was loaded // or is not currently available, start a load. forceLoad(); } }
有事.. 先到這..
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
