Where does 'Force Stop` leave an Activity in its life cycle?

ε祈祈猫儿з 提交于 2019-12-04 10:13:24

When you force stop an application you outright kill it and nothing lives. No methods are called, nothing. This is different than the system killing the app to preserve memory. Force closing is not meant to be sweet, it is meant to kill the awry app so it stops being wasteful.

So the next time you open up your app, it starts from the beginning - the MainActivity. Which is why force stopping "may cause an app to misbehave". You might have stopped it in the middle of doing something useful - like writing to a server/file system, etc. This is why you should make your app as efficient as possible or code it in such a way that it can handle unexpected closures. This can mean staying away from long tasks and saving fast and often.

Since force stop is designed to by used when your application is not responsive, it does not generate any callbacks, but removes your process. As such, you should should see the same log messages as if you launched your activity fresh from "ActivityStart", so starting with onCreate(). As to why you are not seeing the logging message, I am not sure. Make sure you aren't filtering logcat by PID because your new instance with have a different PID.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!