我有一个例程,每秒多次对SQLite数据库运行不同的查询.过了一会儿,我会得到错误
"android.database.CursorWindowAllocationException: - Cursor window allocation of 2048 kb failed. # Open Cursors = " 出现在LogCat中.
我有应用程序日志内存使用情况,实际上当使用率达到一定限度时,我收到此错误,暗示它用完了.我的直觉告诉我,每次运行查询时数据库引擎都在创建一个新缓冲区(CursorWindow),即使我将.close()标记为游标,垃圾收集器也SQLiteDatabase.releaseMemory()不足以释放内存.我认为解决方案可能在于"强制"数据库始终写入相同的缓冲区,而不是创建新的缓冲区,但我一直无法找到这样做的方法.我已经尝试实例化我自己的CursorWindow,并尝试将其设置为和SQLiteCursor无济于事.
有任何想法吗?
编辑:来自@GrahamBorland的示例代码请求:
public static CursorWindow cursorWindow = new CursorWindow("cursorWindow");
public static SQLiteCursor sqlCursor;
public static void getItemsVisibleArea(GeoPoint mapCenter, int latSpan, int lonSpan) {
query = "SELECT * FROM Items"; //would be more complex in real code
sqlCursor = (SQLiteCursor)db.rawQuery(query, null);
sqlCursor.setWindow(cursorWindow);
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望能够.setWindow()在提供新查询之前,CursorWindow每次获取新数据时都将数据放入相同的数据中.
有谁知道如何SQLiteDatabase.CursorFactory在Android 上使用?我希望获得一个持久的SQLiteCursor对象,该对象使用SQL SELECT语句,其中几个WHERE子句表达式使用可以在重新查询之前以编程方式更改的参数.
例如:
SELECT LocationID FROM Locations WHERE Latitude < northlimit AND Latitude > southlimit AND Longitude < eastlimit AND Longitude > westlimit;
Run Code Online (Sandbox Code Playgroud)
限制参数将每200ms动态变化一次
我试图解决一个问题,如果我只是使用SQLiteDatabase.rawQuery("SELECT ...");系统为每个新查询创建一个新的CursorWindow,最终耗尽内存.所以我试图找到一种方法来强制系统不要创建新的CursorWindows.
我们编写了一个新版本的 Android 应用程序来升级旧的应用程序,但希望在升级后第一次运行时从旧应用程序 SharedPreferences 中提取登录用户名,然后用新数据模型覆盖整个内容。新代码库的 build.gradle 指定了更新的 versionName 和 versionCode,但是当我们尝试从 Android Studio 运行到安装了旧应用程序的设备上时,我们会收到一个包含以下错误消息的对话框:
Installation failed since the device already has a newer version of this application.
In order to proceed, you have to uninstall the existing application.
WARNING. Uninstalling will removed the application data!
Do you want to uninstall the existing application?
[OK] [Cancel]
Run Code Online (Sandbox Code Playgroud)
显然,如果我们接受它会卸载旧应用程序以及所有用户数据,我们将无法实现我们的预期。
无法在互联网上找到有关此问题的任何信息
旧APP build.gradle:
versionCode 1
versionName '1.4.1'
Run Code Online (Sandbox Code Playgroud)
新应用程序 build.gradle:
versionCode 2
versionName '2.0.0'
Run Code Online (Sandbox Code Playgroud) 有没有办法在Dart中使用现有的Polymer 标准核心元素,例如核心工具栏和核心菜单?
如果您使用bower下载聚合物项目,您可以在中找到javascript版本/polymer/bower-components/.
例如,核心工具栏包含a core-toolbar.html和a metadata.html.这些<polymer-element>标签就像在Dart中一样.这些可以改编吗?
android ×3
cursor ×2
sqlite ×2
apk ×1
dart ×1
dart-polymer ×1
dart-webui ×1
memory ×1
memory-leaks ×1
polymer ×1
upgrade ×1
version ×1