Reputation: 1199
According to Android documentation :
android:multiprocess
Whether or not an instance of the content provider can be created in every client process — "true" if instances can run in multiple processes, and "false" if not. The default value is "false".
Normally, a content provider is instantiated in the process of the application that defined it. However, if this flag is set to "true", the system can create an instance in every process where there's a client that wants to interact with it, thus avoiding the overhead of interprocess communication.
Therefore, if this attribute is set to true
then an instance of Content Provider will be created in every process.
Question 1 Is this instance a reference to the content provider or a copy of the whole content provider?
Question 2 How does the system handle syncing changes back to the default / original implementation? Is it that the data source (SQLite, etc.) takes care of the multi-process read / writes?
Question 3 This is more of an educated guess. Originally, there is content provider instance at the application that owns the content provider. Everytime the other apps interact with it, they do so through IPC, which means this :
other app --> IPC --> content provider --> data source
When multiprocess="true"
is set, the system creates a copy of the content provider in each process. Therefore, the app does not have to go through IPC to interact with the content provider.
other app ---> content provider ---> data source
The content provider can still directly access the data source. In this case, its methods must be thread/process safe, since other apps will be accessing it as well.
If this scenario is correct, is this thread-safety implementation different from the default requirement of thread-safety?
Upvotes: 10
Views: 2048
Reputation: 4775
Good Questions, sadly I found an answer and it's: Don't use this attribute.
Don't use this, it is some old cruft from pre-1.0 design that doesn't work and should be ignored these days. Just pretend like the attribute doesn't exist. :}
...
Dianne Hackbor
Android framework engineer
https://groups.google.com/forum/#!topic/android-developers/u9UMJtALSXw
I created an issue requesting that this will be properly documented: https://code.google.com/p/android/issues/detail?id=217916
UPDATE Dec 2020 (6 years later): Issue is still not addressed, I've opened a new report here: https://issuetracker.google.com/issues/175708197
Upvotes: 18