in-Memory Content Provider

问题描述 投票:2回答:1

我想使用内容提供者作为Android中不同应用之间的进程间通信机制。

假设主应用也充当内容提供商。我希望该应用程序下载大量数据并将其存储在内存中(无需在磁盘上写入数据),然后使用内容提供程序将此数据传递给其他应用程序。其他应用程序将获取意图中的内容URI,并从该内容URI中读取数据。

我在这方面的问题是,是否可以通过主应用将数据存储在内存中,然后让内容提供商发送该数据。内容提供商的生命周期是否可以做到这一点?

android android-contentprovider
1个回答
1
投票

这是我发现的内存内容提供程序的最佳示例之一。https://gist.github.com/m039/6550133


另一个简单的方法是将空值传递给SQLiteOpenHelper构造函数参数:名称。

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

    /**
 * 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);
}
© www.soinside.com 2019 - 2024. All rights reserved.