Chinaunix首页 | 论坛 | 博客
  • 博客访问: 835202
  • 博文数量: 244
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 2420
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-29 09:07
文章分类

全部博文(244)

文章存档

2011年(4)

2010年(3)

2009年(72)

2008年(119)

2007年(46)

我的朋友

分类: LINUX

2009-05-11 02:31:33

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) |
0

上一篇:Android 虚拟机 Dalvik

下一篇:wifi子系统分析

给主人留下些什么吧!~~

chinaunix网友2010-06-02 12:29:51

就这JB代码转贴100W次了!能有点原创不?