Anko6
Anko6

Reputation: 41

What is the difference between android shared memory api and content provider?

Android shared memory api(which is introduced in api 27) is used for sharing data between different process. So is it a replacement of content provider?

Upvotes: 0

Views: 1228

Answers (1)

nhoxbypass
nhoxbypass

Reputation: 10152

If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs, but it is not multi-process safe.

SharedMemory API (which introduce in Android 8) allows you to reading and/or writing file descriptor using NDK, since the SharedMemory object is Parcelable, you can easily pass it to another process through AIDL. It's a great way to set the memory protection and share large amounts of data between apps or between multi-process within a single app.

ContentProviders were constructed for sharing data between apps. A content provider presents data to external applications as one or more tables that are similar to the tables found in a relational database. You can create your own ContentProvider which stores the data with a SharedPreference, you don't have to use SQLite. The ContentProvider APIs are well suited for SQL type implementations.

Upvotes: 1

Related Questions