startservice執行的生命週期:
startservice —> oncreate() —>onstartcommand() —> ondestroy()—>結束
①啟動服務/startservice()
單次:oncreate() —> onstartcommand()
多次:oncreate() —>onstartcommand() —>>onstartcommand() ……
注意:多次啟動服務oncreate()只會執行一次,onstartcommand()會執行多次;
②停止服務/stopservice()
ondestroy()
bindservice執行的生命週期:
bindservice—>oncreate() —>onbind() —>onunbind() —>ondestroy()
①繫結服務/bindservice()
oncreate() —>onbind()
②解綁服務/unbindservice()
onunbind() —>ondestroy()
先startservice後bindservice的生命週期:
oncreate() —>onstartcommand() —>onbind() —>onunbind() —> ondestroy()
①啟動繫結服務/startservice()、bindservice()
oncreate() —>onstartcommand() —> onbind()
②停止解綁服務/stopservice()、unbindservice()
onunbind() —> ondestroy()
先bindservice後startservice的生命週期:
oncreate() —> onbind() —>onstartcommand() —>onunbind() —>ondestroy()
①繫結啟動服務/bindservice()、startservice()
oncreate() —>onbind() —>onstartcommand()
②解綁停止服務/unbindservice()、stopservice()
onunbind() —>ondestroy()
解綁再繫結服務/unbindservice()、bindservice()
onunbind(ture) —>onrebind()
service生命週期
service 生命週期 注意 onstart方法是在android2.0之前的平台使用的.在2.0及其之後,則需重寫onstartcommand方法,同時,舊的onstart方法則不會再被呼叫.1 可以通過呼叫 context.startservice 啟動乙個 service 這可能會觸發 se...
Service生命週期
1 通過startservice開啟服務 oncreate onstartcommand 2 通過stopservice關閉服務 ondestroy 說明 如果在未stopservice的情況下,再去startservice,只會onstartcommand 3 通過bindservice開啟服務 ...
Service生命週期
service生命週期 使用context.startservice 啟動service 其生命週期為context.startservice oncreate onstart service running context.stopservice ondestroy service stop 如果...