English 中文(简体)
穿过LQ Cur,需要太多时间
原标题:Looping through a SQLite Cursor takes too much time

我正在使用<代码>SQLite关于安乐施和<代码>植被的数据库。 我认为,我撰写的所有方法需要太多时间。

这是我所说的话:

public static List<Feed> getAll(Context context) {
        List<Feed> feeds = new ArrayList<Feed>();
        Uri allFeeds = Uri.parse(ContentProvidersUris.URL_CONTENT_PROVIDER_FEED);

        long startQuery = BenchmarkUtils.start();
        Cursor c = context.getContentResolver().query(allFeeds, null, null, null, "title desc");

        long startCursor = BenchmarkUtils.start();
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            long startInsideCursor = BenchmarkUtils.start();

            Feed feed = new Feed();
            feed.setContent(c.getString(c.getColumnIndex(FeedsProvider.COL_WEBVIEW_CONTENT)));
            feed.setDate(c.getString(c.getColumnIndex(FeedsProvider.COL_PUB_DATE)));
            feed.setDescription(c.getString(c.getColumnIndex(FeedsProvider.COL_DESCRIPTION)));
            feed.setName(c.getString(c.getColumnIndex(FeedsProvider.COL_FEED_NAME)));

            Log.d(TAG, "This loop  cursor iteration took : " + BenchmarkUtils.stop(startInsideCursor) + " ms.");
        }

        Log.d(TAG, "Looping through the ENTIRE Cursor took: " + BenchmarkUtils.stop(startCursor) + " ms.");


        return feeds;
}

你可以看到,我也正在衡量这一休息时间,因此,它平均需要1800 ms。 (Nexus S)。 我认为,这是很多时候。 我不理解的是,大部分时间是用在“上,时间是“。 如记录所示:

D/FeedsProviderHelper(5800):这种 lo形曲线透水:1726条。

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:2 ms。

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:2 ms。

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper( 5800): This loop cursor iteration took : 3 ms.

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:2 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:零。

D/FeedsProviderHelper(5800):这种 lo形曲线的消旋:5 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:1 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:1 ms。

D/FeedsProviderHelper(5800):这种 lo形曲线的消旋:5 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:1 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:1 ms。

D/FeedsProviderHelper(5800):这种 lo曲器的消旋:1 ms。

D/FeedsProviderHelper( 5800): Looping through the ENTIRE Cursor took: 1770 ms.

So my questions are:

是否正常? 如果是,为什么? 如果不是的话,我会做什么错呢? 加速填写<代码>的所有 对照KQite数据库?

感谢!

EDIT

我使用了getColumnIndex。 用“@superfell”建议的语句中,现在我使用的是getAll,平均1500ms。 我认为(ain)快但还不够快!

最佳回答

Is it normal?

Sure。

如果是,为什么?

I/O号楼的费用非常昂贵,特别是在闪电上。 问题本身是应你对<代码>Cursor的首次实际请求而实施的,这就是为什么你的第一个“煽动”已经花了很长的时间。

选择更快的方式 所有这些都针对Kalk数据库?

第一,你不再对库马库特数据库进行“电子所有”。 您对内容提供商做“选择”。

采用追踪调查准确确定贵国何时处理,并相应调整适用。 例如,你可能认为,首先不要将<代码>Cursor中的数据复制到一份POJOs清单中是更有意义的。

问题回答

你们应该做的第一个事情是把ColumnIndex的电话带出坡道,这些话花了钱,你只需要一劳永逸地这样做。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签