本文介绍了安卓光标movetofirst性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图优化我的申请。我注意到,cursor.movetofirst()方法在某种程度上减缓我的code的性能。

 光标光标= myDbHelper.getDayInfo(新的SimpleDateFormat(YYYY-MM-DD)格式(myCalendar.getTime());

上面的一行在执行 10毫秒中的 2.1模拟器

 如果(光标= NULL&放大器;!&安培; cursor.moveToFirst())

此行历时约1.6秒。我做了这个小的搜索。 Somepeople说,使它在另一个线程或AsyncTask的,但是这会令code更为复杂。
我只是想弄清楚什么是真正发生在这个光标。
任何人都可以简化或给予有关与我的问题数据库性能提高的暗示?


解决方案

这是很自然的,即moveToFirst()方法获取更多的时间,其他code。数据enquariyng实际发生,这将调用数据库通信,数据读出等。事实上,你不能用它做任何事情。这个建议是正确的 - 将所有长操作

i am trying to optimize my application. I noticed that cursor.movetofirst() method somehow slowing the performance of my code.

Cursor cursor = myDbHelper.getDayInfo(new SimpleDateFormat("yyyy-MM-dd").format(myCalendar.getTime());

above line executes in 10 ms in 2.1 emulator, and

if(cursor != null && cursor.moveToFirst()) 

this line took about 1.6 seconds. I made little search about this. Somepeople say make it in another thread or in asynctask, but this will make the code more complicated.I 'm just trying to figure out what is actually happening to this cursor.Can anyone simplify or give a hint about database performance increase related to my question?

解决方案

It is natural, that moveToFirst() method gets much more time that other code. The data enquariyng actually takes place, which invokes database communication, data reading and so on. You actually can't do anything with it. The advice was right - move all the long operations to AsyncTask.

这篇关于安卓光标movetofirst性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:36