内存内容提供程序

3
我希望能够在Android中使用内容提供程序作为不同应用程序之间的进程间通信机制。 假设主应用程序也充当内容提供程序。我想让应用程序下载大量数据并将其存储在内存中(而不是写入磁盘),然后通过内容提供程序将此数据传递给其他应用程序。其他应用程序将从意图中获取内容URI,并从该内容URI读取数据。
我的问题是,主应用程序是否可以将数据存储在内存中,并让内容提供程序发送该数据。内容提供程序的生命周期是否允许这样做?
1个回答

2

这是我发现的一个最好的内存内容提供程序示例。

https://gist.github.com/m039/6550133

另一种简单的方法是将null值传递给SQLiteOpenHelper构造函数的参数:name。

所有其他操作(插入/更新/删除/查询)与磁盘上的写操作相同。

    /**
 * Create a helper object to create, open, and/or manage a database.
 * This method always returns very quickly.  The database is not actually
 * created or opened until one of {@link #getWritableDatabase} or
 * {@link #getReadableDatabase} is called.
 *
 * @param context to use to open or create the database
 * @param name of the database file, or null for an in-memory database
 * @param factory to use for creating cursor objects, or null for the default
 * @param version number of the database (starting at 1); if the database is older,
 *     {@link #onUpgrade} will be used to upgrade the database; if the database is
 *     newer, {@link #onDowngrade} will be used to downgrade the database
 */
public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version) {
    this(context, name, factory, version, null);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接