ContentProvider既可以与调用方处在同一进程,也可以运行在单独进程中,完全取决于ContentProvider所处的aplication的进程信息。因此假如ContentProvider运行在单独的进程中,那么调用ContentProvider将会涉及到IPC通信。
既然涉及到IPC通信,那么ContentProvider一定继承自IInterface,这个IInterface就是IContentProvider,其主要的接口方法如下,
public IBulkCursor bulkQuery(Uri url, String[] projection,
String selection, String[] selectionArgs, String sortOrder, IContentObserver observer,
CursorWindow window) throws RemoteException;
public Cursor query(Uri url, String[] projection, String selection,
String[] selectionArgs, String sortOrder) throws RemoteException;
public String getType(Uri url) throws RemoteException;
public Uri insert(Uri url, ContentValues initialValues)
throws RemoteException;
public int bulkInsert(Uri url, ContentValues[] initialValues) throws RemoteException;
public int delete(Uri url, String selection, String[] selectionArgs)
throws RemoteException;
public int update(Uri url, ContentValues values, String selection,
String[] selectionArgs) throws RemoteException;
public ParcelFileDescriptor openFile(Uri url, String mode)
throws RemoteException, FileNotFoundException;
public AssetFileDescriptor openAssetFile(Uri url, String mode)
throws RemoteException, FileNotFoundException;
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws RemoteException, OperationApplicationException;
但是阅读ContentProvider代码时,会发现
public abstract boolean onCreate();
public void onConfigurationChanged(Configuration newConfig);
public void onLowMemory();
这几个方法并不在IContentProvider中声明,因此千万注意它们在运行时并不是处在AndroidManifest.xml中声明时的进程中。而是处在调用ContentProvider的应用的进程中的。
因此千万不要在onCreate中添加你期望运行在ContentProvider的进程的代码。
分享到:
相关推荐
使用ContentProvider来实现跨进程间的通信
ContentProvider封装SharedPreferences功能,解决跨进程存取值的问题, 我之前一直用自己封装的SharePreferences,后来出现跨进程问题;就用这个 ContentProvider,真好用,值得拥有!
Android中ContentProvider的示例,详细可以参见博客:http://www.cnblogs.com/plokmju/p/android_ContentProvider.html
单例模式在单进程中用的很爽,但在多进程就鸡肋了 使用AIDL完成的稳定性和效率并不是很高,本人做的项目拉取AIDL传来的值一直存在不稳定的问题 最后一个问题最蛋疼。造成最后一个问题的原因是多方面的,最主要的原因...
ContentProvider在android中的作用是对外共享数据;本实例实现了对数据的增删改查操作
android 自定义 ContentProvider 以及 ContentResolver
contentprovider
ContentProvider自定义以及使用系统ContentProvider
1、Android Room操作SQLite数据 2、ContentProvider使用,使用Room进行数据库操作
ContentProvider概述 ContentProvider概述 ...ContentProvider概述ContentProvider概述ContentProvider概述ContentProvider概述ContentProvider概述 ContentProvider概述ContentProvider概述ContentProvider概述
介绍ContentProvider使用方法,包括最简单的用法,一个项目中创建多个ContentProvider分别操作数据库表,以及一个ContentProvider操作多张数据库表的用法。
程序例子包含了2个独立的Android程序,其中一个负责提供数据并提供本地操作,另外一个可以跨进程访问提供者提供的数据。例子虽然简单,但是覆盖到了Content Provider里面的知识点,例如集成Content Provider,Uri的...
android中使用contentprovider编写简单的通讯录的简单实例 希望能给大家帮助
contentProvider 的使用以及总结
一看就会简单易学,contentProvider连接数据库;有注解,有注释,
ContentProvider 共享SharedPreferences 值
android contentprovider使用示例
contentProvider监听的例子
androdi ContentProvider和Uri详解
ContentProvider项目