`
huobengluantiao8
  • 浏览: 1031421 次
文章分类
社区版块
存档分类
最新评论

运行在单独进程中的ContentProvider

 
阅读更多

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的进程的代码。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics