Android的内容提供商的数据库泄漏问题 [英] Android Content Provider database leak issue

查看:158
本文介绍了Android的内容提供商的数据库泄漏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的内容提供这个应用程序,并在我的内容提供商,我打开一个数据库连接,运行查询并返回结果的光标移动到调用程序。如果我关闭了提供该数据库连接,光标一直没有结果。如果我离开它打开,我得到发现泄露以我DDMS日志错误。我在想什么吗?什么是干净的,正确的方式返回游标数据库的结果?

I am writing a content provider for this application and in my content provider I am opening a database connection, running a query and returning the cursor of results to the calling program. If I close this database connection in the provider, the cursor has no results. If I leave it open, I get "leak found" errors in my DDMS log. What am I missing here? What's the clean, proper way to return a cursor of database results?

推荐答案

您不会错过任何东西AFAIK。安卓缺少一个的onDestroy()(或等值)的的ContentProvider 。甚至没有在源$ C ​​$ C在此区域说明什么有某种的onDestroy的(),只是没有在SDK中浮出水面。

You're not missing anything AFAIK. Android is missing an onDestroy() (or the equivalent) for ContentProvider. There isn't even anything in the source code in this area that suggests there is some sort of onDestroy() that just isn't surfaced in the SDK.

如果你看一下源$ C ​​$下 AlarmProvider LauncherProvider ,他们甚至创建数据库对象上每个API呼叫的基础上(例如,每次他们得到插入(),他们打开一个可写的数据库处理,他们从来没有关闭)。

If you look at the source code for AlarmProvider and LauncherProvider, they even create database objects on a per-API-call basis (e.g., every time they get insert(), they open a writable database handle that they never close).

这篇关于Android的内容提供商的数据库泄漏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆