Android插件化架构 - Activity的启动流程分析

.startActivity(whoThread, who.getBasePackageName(), intent,

intent.resolveTypeIfNeeded(who.getContentResolver()),

token, target != null ? target.mEmbeddedID : null,

requestCode, 0, null, options);

checkStartActivityResult(result, intent);

} catch (RemoteException e) {

throw new RuntimeException(“Failure from system”, e);

}

return null;

}

// 检测结果也就是否正常

public static void checkStartActivityResult(int res, Object intent) {

if (res >= ActivityManager.START_SUCCESS) {

return;

}

switch (res) {

case ActivityManager.START_INTENT_NOT_RESOLVED:

case ActivityManager.START_CLASS_NOT_FOUND:

// 在这里就会报各种错,AndroidManifest.xml中没有配置的错就出现在这

if (intent instanceof Intent && ((Intent)intent).getComponent() != null)

throw new ActivityNotFoundException(

"Unable to find explicit activity class "

  • ((Intent)intent).getComponent().toShortString()

  • “; have you declared this activity in your AndroidManifest.xml?”);

throw new ActivityNotFoundException(

"No Activity found to handle " + intent);

case ActivityManager.START_PERMISSION_DENIED:

throw new SecurityException("Not allowed to start activity "

  • intent);

case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:

throw new AndroidRuntimeException(

“FORWARD_RESULT_FLAG used while also requesting a result”);

case ActivityManager.START_NOT_ACTIVITY:

throw new IllegalArgumentException(

“PendingIntent is not an activity”);

case ActivityManager.START_NOT_VOICE_COMPATIBLE:

throw new SecurityException(

"Starting under voice control not allowed for: " + intent);

case ActivityManager.START_VOICE_NOT_ACTIVE_SESSION:

throw new IllegalStateException(

“Session calling startVoiceActivity does not match active session”);

case ActivityManager.START_VOICE_HIDDEN_SESSION:

throw new IllegalStateException(

“Cannot start voice activity on a hidden session”);

case ActivityManager.START_CANCELED:

throw new AndroidRuntimeException("Activity could not be started for "

  • intent);

default:

throw new AndroidRuntimeException("Unknown error code "

  • res + " when starting " + intent);

}

}

ActivityManagerNative.getDefault().startActivity又是一个进程间的通信,如果不了解IPC的请移步 Android进程间的通信 - IPC(机制)Binder的原理和源码阅读,来到ActivityManagerService中的startActivity方法:

@Override

public final int startActivity(IApplicationThread caller, String callingPackage,

Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,

int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) {

return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo,

resultWho, requestCode, startFlags, profilerInfo, bOptions,

UserHandle.getCallingUserId());

}

@Override

public final int startActivityAsUser(IApplicationThread caller, String callingPackage,

Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,

int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) {

enforceNotIsolatedCaller(“startActivity”);

userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),

userId, false, ALLOW_FULL_ONLY, “startActivity”, null);

// TODO: Switch to user app stacks here.

return mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent,

resolvedType, null, null, resultTo, resultWho, requestCode, startFlags,

profilerInfo, null, null, bOptions, false, userId, null, null);

}

final int startActivityMayWait(IApplicationThread caller, int callingUid,

String callingPackage, Intent intent, S

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值