When Android kills an app, can a function be stopped halfway?

后端 未结 7 2132
青春惊慌失措
青春惊慌失措 2020-12-10 03:30

I am wondering: when an app is to be killed, does Android wait for the currently running function to return, or does Android stop it before it ends by itself?

7条回答
  •  没有蜡笔的小新
    2020-12-10 04:15

    It would make sense that it would kill a method mid-execution. Consider that many "hangs" are due to an infinite loop condition within a single method's loop. How else would an OS kill such an app without killing it in the middle of executing a method?

    Also consider this: Even if an OS allowed the "current" method to finish executing before killing the app, and then killed the app, it would then be killing the app in the middle of the method that had called the first method that the OS allowed to continue executing until it finished. OK, so then continue this thinking to its extreme. If the OS allowed each function that was in the middle of executing to finish before killing the app, then the end result is that the OS allows the entire app to run to completion, which is exactly what killing an app is supposed to circumvent. Thus, an OS, when killing an app, must terminate it in the middle of "a"... acutally "many".... functions. Every function that's on the callstack does NOT get a chance to finish!

提交回复
热议问题