學習Contentprovider
Uri的格式:“content://”+authority+“/表名”
字符串轉成Uri格式:Uri.parse( );
獲取Cursor某一項的數據:
Cursor 先鎖定某一行:如cursor.movetofirst( );
Cursor 再根據列名鎖定某一列,最後取出數據:cursor.getvaluesType (cursor.getcolumnindex( “ 列名”))
Contentprovider內容提供者 先其他進程提供共享數據,而contentResolver則作爲其他進程再向contentprovider索要數據是的客服。
怎麼使用contentprovider
1.在AndroidManifest.xml 文件中首先聲明 要創建的contentprovider的屬性:
如:<provider
android:name = “com.wade.test.MyProvider”;
anroid:authorities=”com.test.provider”
/>
anroid:authorities表示的是contentprovider的標識,當在activity向contentResolver發出請求的時候,contentResolver會根據authorities的值跳到對應的contentprovider的程序來執行。
如:getcontentResolver().insert( Uri.parse(“content:// com.test.provider/表名”) , values );
這樣程序之後會跳到 “com.wade.test.MyProvider”來執行相應的代碼。
2.創建contentprovider相關的類
創建一個類繼承contentprovider並重寫相應函數,
創建一個類繼承SQLopenHelper,並實例化一個對象,利用這個對象來操作數據庫