1. 程式人生 > >Android Service生命週期理解

Android Service生命週期理解

Android  有兩種啟動模式

1、bindService()

2、startService()

startService生命週期

oncreate-->onstart-->onstartcommand--> service runing--->(stopService)--->onDestroy

1、當多次呼叫startService時,如果service沒有建立則會先建立Service呼叫Oncreate-->然後呼叫onstart

2、如果startService時,service已經建立了就呼叫onstart()可多次呼叫。

bindService

oncreate-->onbind--->service running-->unbind--->ondestroy

                                                                                    ---->onrebind---->onbind--->service running

1、unbind什麼時候被呼叫呢,當unbind之後,ondestroy之前又有coentext對他進行bind繫結,則會呼叫onrebind()