Android Service LifeCycle

根據Android Service的類型,主要有如下幾種值得注意的Service聲明週期:對象

一、Service-Started LifeCycle生命週期

這種是對應經過Context.StartService啓動的service生命週期。onCreate->onStart(若是被屢次Context.StartService調用,則該方法也被調用屢次,須要注意的是Service對象不會建立多個)------------>end onDestroy(Context.StopService或者stopSelf)service

二、Service-Bound LifeCycle方法

這種是對應BindService的生命週期。onCreate以後不像StartService那樣,不會通過onStart,最後onDestroy.top

三、Service-Started And -Bound LifeCyclevi

這種service是既容許Start又容許Bind的,所以,這種Service的onCreate跟onStart都會被調用。最後onDestroy。tar

相關文章
相關標籤/搜索