學習Contentproviderandroid
Uri的格式:「content://」+authority+「/表名」數據庫
字符串轉成Uri格式:Uri.parse( );ide
獲取Cursor某一項的數據:函數
Cursor 先鎖定某一行:如cursor.movetofirst( );學習
Cursor 再根據列名鎖定某一列,最後取出數據:cursor.getvaluesType (cursor.getcolumnindex( 「 列名」))spa
Contentprovider內容提供者 先其餘進程提供共享數據,而contentResolver則做爲其餘進程再向contentprovider索要數據是的客服。 xml
怎麼使用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,並實例化一個對象,利用這個對象來操做數據庫