What happens when all activities of an application finishes?

前端 未结 4 1535
南方客
南方客 2020-12-28 08:24

Scenario:

I\'ve four activities in my Android Application, lets say A, B, C and D. There is one Constants.java class in the app which extends App

4条回答
  •  星月不相逢
    2020-12-28 08:40

    1) No, Android does not guarantee so. It's up to the OS to decide whether to terminate the process or not.

    2) Because the Activity instance still lives in the Dalvik VM. In Android each process has a separate Dalvik VM.

    Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

    When you call finish() this doesn't mean the Activity instance is garbage collected. You're telling Android you want to close the Activity (do not show it anymore). It will still be present until Android decides to kill the process (and thus terminate the DVM) or the instance is garbage-collected.

    Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications.

    3) I wouldn't do so unless you have some very strong reason. As a rule of thumb, you should let Android handle when to kill your application, unless there's something in your application state that requires an application reset when it loses focus.

    Quotes source

提交回复
热议问题