专栏名称: 安卓开发精选
伯乐在线旗下账号,分享安卓应用相关内容,包括:安卓应用开发、设计和动态等。
目录
相关文章推荐
51好读  ›  专栏  ›  安卓开发精选

Android Service的启动过程(上)

安卓开发精选  · 公众号  · android  · 2016-11-08 22:45

正文

请到「今天看啥」查看全文


Binder . restoreCallingIdentity ( origId );

return res ;

}

}


在上述的代码中,调用了ActiveServices的startServiceLocked方法,那么现在Service的启动过程从AMS转移到了ActiveServices了。


继续跟进ActiveServices的startServiceLocked方法,如下:


ComponentName startServiceLocked ( IApplicationThread caller , Intent service , String resolvedType ,

int callingPid , int callingUid , String callingPackage , int userId )

throws TransactionTooLargeException {

//代码省略

ServiceLookupResult res =

retrieveServiceLocked ( service , resolvedType , callingPackage ,

callingPid , callingUid , userId , true , callerFg );

//代码省略

ServiceRecord r = res . record ;

//代码省略

return startServiceInnerLocked ( smap , service , r , callerFg , addToStarting );

}


在startServiceLocked方法中又会调用startServiceInnerLocked方法,


我们瞧瞧startServiceInnerLocked方法,


ComponentName startServiceInnerLocked ( ServiceMap smap , Intent service , ServiceRecord r ,

boolean callerFg , boolean addToStarting ) throws TransactionTooLargeException {

ProcessStats . ServiceState stracker = r . getTracker ();

if ( stracker != null ) {

stracker . setStarted ( true , mAm . mProcessStats . getMemFactorLocked (), r . lastActivity );

}

r . callStart = false ;

synchronized ( r . stats . getBatteryStats ()) {

r . stats . startRunningLocked ();

}

String error = bringUpServiceLocked ( r , service . getFlags (), callerFg , false );

//代码省略

return r .







请到「今天看啥」查看全文