aaa
数据库流程分析
通过intent 添加或者编辑contact
intent = new Intent(Intent.ACTION_INSERT, People.CONTENT_URI);
intent = new Intent(Intent.ACTION_EDIT,
ContentUris.withAppendedId(People.CONTENT_URI, id));
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(intent);
EditContactActivity.java (packages\apps\contacts\src\com\android\contacts)
protected void onCreate(Bundle icicle)
buildEntriesForInsert(getIntent().getExtras());
doSaveAction
save()
mResolver.insert(entry.uri, values);
EditContactActivity.java (packages\apps\contacts\src\com\android\contacts)文件类
public final class EditContactActivity extends Activity implements View.OnClickListener,
TextWatcher, View.OnFocusChangeListener 中有:
ContentResolver mResolver;
public abstract class ContentResolver
public final Uri insert(Uri url, ContentValues values)
IContentProvider provider = acquireProvider(url);
return provider.insert(url, values);
调用:
===========================
public abstract class ContentProvider implements ComponentCallbacks
class Transport extends ContentProviderNative
public Uri insert(Uri uri, ContentValues initialValues)
return ContentProvider.this.insert(uri, initialValues)
public int bulkInsert(Uri uri, ContentValues[] initialValues)
return ContentProvider.this.insert(uri, initialValues)
public int bulkInsert(Uri uri, ContentValues[] initialValues)
public abstract class SyncableContentProvider extends ContentProvider
public abstract class AbstractSyncableContentProvider extends SyncableContentProvider
===========================
public final Uri insert(final Uri url, final ContentValues values)
result = insertInternal(uri, values[i]);
public final int bulkInsert(final Uri uri, final ContentValues[] values)
Uri result = insertInternal(url, values);
因为:
public class ContactsProvider extends AbstractSyncableContentProvider
所以:
Uri result = insertInternal(url, values);执行的是 ContactsProvider 类中的
public Uri insertInternal(Uri url, ContentValues initialValues)函数
final SQLiteDatabase db = getDatabase();
int match = sURIMatcher.match(url);
switch(match)
case PEOPLE_OWNER:
return insertOwner(initialValues);
case PEOPLE_RAW:
case PEOPLE:
rowID = mPeopleInserter.insert(mValues);
因为 ContactsProvider 类中有:
private DatabaseUtils.InsertHelper mPeopleInserter;
public class DatabaseUtils
public static class InsertHelper
public long insert(ContentValues values)
private synchronized long insertInternal(ContentValues values, boolean allowReplace)
QLiteStatement stmt = getStatement(allowReplace);
return stmt.executeInsert();
native_execute();
本地调用:
android_database_SQLiteStatement.cpp (frameworks\base\core\jni)
static void native_execSQL(JNIEnv* env, jobject object, jstring sqlString)
jchar const * sql = env->GetStringChars(sqlString, NULL);
jsize sqlLen = env->GetStringLength(sqlString);
err = sqlite3_prepare16_v2(handle, sql, sqlLen * 2, &statement, NULL);
完成数据库操作。
public class CalendarProvider extends AbstractSyncableContentProvider
阅读(1184) | 评论(1) | 转发(0) |