I have a ContentProvider subclass doing all my database work, and a Service that is running in the background.
I can't seem to be able to bind a Service to the ContentProvider. Can I call a method from the service within the ContentProvider at all, or is there a way to bind?
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.
Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications.
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.
A content provider is a subclass of ContentProvider that supplies structured access to data managed by the application. All content providers in your application must be defined in a <provider> element in the manifest file; otherwise, the system is unaware of them and doesn't run them.
I binded the service in the onCreate() method
@Override
public boolean onCreate() {
mContext = getContext();
.. do other things
doBindService();
return true;
}
and then used the context to actually bind the service
void doBindService() {
mContext.bindService(new Intent(mContext,
SomeService.class), mConnection, Context.BIND_AUTO_CREATE);
}
I don't unbind from the service, but it seems to work ok
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