- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用来自 commonsware 的 sqlitecursorloader 库。我在 Intentservice 中收到 GCM 消息,并想在 sqlite 数据库中插入一个条目。如果应用程序打开,它应该更新 ListView 。
我尝试在加载程序初始化的 Activity 中使用它:
public static void createDbEntry(String Title, String Message) {
ContentValues values=new ContentValues(2);
values.put(DatabaseHelper.TITLE, Title);
values.put(DatabaseHelper.MESSAGE, Message);
loader.insert("constants", DatabaseHelper.TITLE, values);
}
在 intentservice 中:
MainActivity.createDbEntry(title,message);
据我所知,这在大多数情况下都有效,但如果加载程序被回收,我会得到一个空指针。
我应该在 intentservice 中初始化一个新的加载器吗?
请帮忙,我是 android 开发的新手。
最佳答案
将 Loader
放在静态数据成员中是不好的,对于任何 Loader
,更不用说 SQLiteCursorLoader
,因为你会泄漏你的 Activity
。
我现在也正式停止使用 SQLiteCursorLoader
。
或者:
切换到使用 ContentProvider
和常规 CursorLoader
,或者
使用事件总线(LocalBroadcastManager
、Square 的 Otto、greenrobot 的 EventBus 等)让您的服务通知您的 UI 层根据您的更改自行刷新
关于android - 使用 sqlitecursorloader 从 intentservice 插入到 sqlite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22559944/
我正在使用基于 ActionBarSherlock 的 Activity 和 fragment 。要从 SQLite 数据库中读取行,我尝试使用 Loader 而不是 ContentProvider,
我正在重构一个 Android 开发中的应用程序以使用 Loader 框架,并且由于数据全部存储在 SQLite 数据库中,我使用的是 commonsware loaderex 包和 SQLiteCu
我正在使用来自 commonsware 的 sqlitecursorloader 库。我在 Intentservice 中收到 GCM 消息,并想在 sqlite 数据库中插入一个条目。如果应用程序打
我是一名优秀的程序员,十分优秀!