gpt4 book ai didi

android - 内存内容提供者

转载 作者:行者123 更新时间:2023-11-29 01:41:45 25 4
gpt4 key购买 nike

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

假设主应用程序也充当内容提供者。我希望该应用程序下载大量数据并将其存储在内存中(不写入磁盘)并使用内容提供商将这些数据传递给其他应用程序。其他应用将获取 Intent 中的内容 URI,并从该内容 URI 中读取数据。

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

最佳答案

这是我发现的内存内容提供程序的最佳示例之一。 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);
}

关于android - 内存内容提供者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24152226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com