ContentProvider启动流程示例解析

  private void handleBindApplication(AppBindData data) {

  final InstrumentationInfo ii;

  // 创建 mInstrumentation 实例

  if (ii != null) {

  //创建ContextImpl

  final ContextImpl appContext = ContextImpl.createAppContext(this, pi);

  try {

  //创建mInstrumentation实例

  final ClassLoader cl = appContext.getClassLoader();

  mInstrumentation = (Instrumentation) cl.loadClass(data.instrumentationName.getClassName()).newInstance();

  } catch (Exception e) {}

  } else {

  mInstrumentation = new Instrumentation();

  }

  Application app;

  try {

  // 创建 Application 实例

  app = data.info.makeApplication(data.restrictedBackupMode, null);

  mInitialApplication = app;

  // 如果不是backup模式,则调用installContentProvider,启动ContentProvider

  if (!data.restrictedBackupMode) {

  if (!ArrayUtils.isEmpty(data.providers)) {

  //启动ContentProvider

  installContentProviders(app, data.providers);

  mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000);

  }

  }

  try {

  //调用Application的onCreate

  mInstrumentation.callApplicationOnCreate(app);

  } catch (Exception e) { }

  }

  }