简体   繁体   English

Android Java:SQLite上的游标在模拟器和某些设备上运行缓慢

[英]Android Java: Cursor on SQLite slow on emulator and some devices

I released an app some weeks ago and many of my users are complaining about the low speed of the app. 几周前,我发布了一个应用程序,许多用户抱怨该应用程序的速度太慢。 When I test my app I'm using a tablet and it works fine without any problem. 当我测试我的应用程序时,我使用的是平板电脑,它运行正常,没有任何问题。

Now I tested the app on the emulator on Android 2.2 and saw that the app is really slow while loading some datas form my SQLite Databse. 现在,我在Android 2.2的模拟器上测试了该应用程序,发现从我的SQLite Databse加载某些数据时,该应用程序确实运行缓慢。 I found out that the Cursor.moveToFirst() Method is extremely slow and forces the emulator to freeze for about 1 minute. 我发现Cursor.moveToFirst()方法非常慢,并迫使模拟器冻结大约1分钟。 This could be the reasson why my users are telling me that there is a forceclose when they open this Activity or the app is slow while loading it :| 这可能是为什么我的用户告诉我打开此Activity或应用在加载它时速度很慢时强制关闭的原因:|

I'm loading up to 700 columns with each only one value. 我正在加载多达700列,每列只有一个值。

What am I doing wrong? 我究竟做错了什么?

Queries are performed on the UI thread by default. 默认情况下,查询是在UI线程上执行的。 It sounds like you are querying an immense amount of information (700 columns worth) and that this is blocking the UI thread for a significant period of time. 听起来您正在查询大量信息(价值700列),并且这在相当长的一段时间内阻塞了UI线程。 You should perform your query asyncronously using a CursorLoader or an AsyncTask so you don't block the UI thread (as if the UI thread is blocked for 4-5 seconds, the app will force close with an "Application not responding" error). 您应该使用CursorLoaderAsyncTask异步执行查询,以免阻塞UI线程(就像UI线程被阻塞4-5秒一样,应用程序将因“应用程序未响应”错误而强制关闭)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM