关闭

onStartCommand after service process is killed when started with START_STICKY

343人阅读 评论(0) 收藏 举报
分类:

http://stackoverflow.com/questions/3963135/onstartcommand-after-service-process-is-killed-when-started-with-start-sticky


When a process is killed and recreated, it goes through the entire lifecycle again (starting at onCreate). Depending on how it was killed and how you save data it may or may not be available to you.

As for getting the intent back, there's a flag for START_REDELIVER_INTENT that will redeliver the intent.

如果service被杀死了,onStartCommand()返回的是START_STICKY,则会重启service,走整个生命周期(重新执行onCreate)。

如果service被杀死了,onStartCommand()返回的是START_REDELIVER_INTENT,则会重启service,走整个生命周期(重新执行onCreate),并且会重新传递Intent。


可以在程序中,使用android.os.Process.killProcess(android.os.Process.myPid());来模拟杀死整个进程,这样子service也就被杀死了。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:659192次
    • 积分:10250
    • 等级:
    • 排名:第1758名
    • 原创:313篇
    • 转载:761篇
    • 译文:1篇
    • 评论:48条