運行在單獨進程中的ContentProvider

來源:互聯網
上載者:User

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的進程的代碼。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.