Why is calling Process.killProcess(Process.myPid()) a bad idea?

前端 未结 6 1840
我寻月下人不归
我寻月下人不归 2020-12-01 06:55

I\'ve read some posts stating that using this method is \"not good\", shouldn\'t be used, it\'s not the right way to \"close\" the application and it\'s not how Android work

6条回答
  •  天涯浪人
    2020-12-01 07:05

    Here are two situations where killProcess will bite you and not work as desired:

    1. Sticky Services - they will restart automatically, even though you killed the process

    2. Timer - if you scheduled threads to run on a Timer, they will continue to execute after killing the process

    Hence, as you can see, there are situations where killProcess is not a prudent solution to clean up your running app.

提交回复
热议问题