1.ContentProvider是什么?
ContentProvider是Android四大组件之一,它为存储和获取数据提供统一的接口,可以在不同的应用程序之间共享数
2.ContentResolver是什么?
通过ContentProvider把应用中的数据共享给其他应用访问,其他应用可以通过ContentProvider对指定应用中的数据进行操作
3.URI是什么?标准是什么?
Uri是:通用资源标识符
uri标准格式:content://com.三级包名/资源路径path
4.UriMatcher是什么
静态代码块:
{
uriMatcher=new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.lenovo.studentprovider","student",1);
uriMatcher.addURI("com.lenovo.studentprovider","teacher",2);
}
5.如何使用ContentProvider
package com.example.xiaozhen.mytest;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by chx on 2018/6/21.
*/
public class StudentSQLite extends SQLiteOpenHelper {
private String student_sql="create table student(" +
"id integer primary key autoincrement not null," +
"name text," +
"age integer" +
")";
public StudentSQLite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL(student_sql);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}