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?
A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.
What is a Content Provider? Whereas the Content Resolver provides an abstraction from the application's Content Providers, Content Providers provide an abstraction from the underlying data source (i.e. a SQLite database).
To access the data from a content provider, URI is used as a query string. Details of different parts of Content URI: content:// – Mandatory part of the URI as it represents that the given URI is a Content URI. authority – Signifies the name of the content provider like contacts, browser, etc.
To the system, a content provider is an entry point into an application for publishing defined data objects, distinguished by a URI design. Thus an application can decide how it requires to draft the data it holds to a URI namespace, giving out those URIs to other objects which can, in turn, use them to reach the data.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With