How to determine if the Android Application was force closed?

后端 未结 2 1225
星月不相逢
星月不相逢 2021-01-21 03:09

I need to determine, if my application was force closed, crashed, or terminated normally. My question is: How would you do such a thing in Android environment. Handling exceptio

相关标签:
2条回答
  • 2021-01-21 03:22

    Unfortunately there is no way. When a user or the system force stops the application, the entire process is simply killed. There is no callback made to inform you that this has happened. Even onDestroy() is not guaranteed to be called. That is documented in the documentation: "There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it ..."

    0 讨论(0)
  • 2021-01-21 03:42

    Perhaps you could write a file on startup that you remove on shutdown. If the app starts and this file is present, you could conclude that it was force-closed.

    0 讨论(0)
提交回复
热议问题