日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

[Loader] 從startLoading()說開去..

系統(tǒng) 1904 0


上一篇主要理了下LoaderCallback, 其中看到LoaderManager在initLoader之后自動調(diào)用了Loader的startLoading方法; 這一篇繼續(xù)理Loader !最后我們就可以把Loader執(zhí)行過程的整個生命周期畫出來了。


先看結(jié)構(gòu)吧,Loader簡單多了。

[Loader] 從startLoading()說開去..

該類源碼查看: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), 然后調(diào)用onStartLoading方法就結(jié)束了, 而onStartLoading方法又是個空方法.. 好了,圓滿結(jié)束!....


尼瑪, 難怪我的loadInBackground方法總是不被調(diào)用! 坑爹啊! 那怎么讓你自己Loader的loadInBackground正常被調(diào)用呢? 只能重寫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();
        }
    }
  

有事.. 先到這..



[Loader] 從startLoading()說開去..


更多文章、技術(shù)交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 林口县| 卓尼县| 玉树县| 辽阳市| 肥西县| 皮山县| 康马县| 南宁市| 长葛市| 永济市| 沙田区| 和顺县| 新邵县| 武邑县| 营口市| 偃师市| 扎赉特旗| 清涧县| 新晃| 岫岩| 深州市| 云霄县| 定安县| 井研县| 兴宁市| 韩城市| 镇雄县| 南阳市| 门头沟区| 两当县| 资中县| 萝北县| 中西区| 多伦县| 民丰县| 镇巴县| 大同县| 邯郸市| 马尔康县| 巢湖市| 陆河县|