我怎样才能做一个Android应用程序之前进行一些清理权利退出?做一个、应用程序、权利、Android

2023-09-12 05:29:43 作者:把眼睛闭着 心里就会懂°

有某种onTerminate()方法,在那里我可以做一些清理(我想清楚了一些共享preferences)时,我的Andr​​oid应用程序将终止?

Is there some sort of onTerminate() method where I can do some cleanup (I want to clear some SharedPreferences) when my Android app is terminating?

我有一个保持几个数字的平均运行的活动,那我存储在共享preference。我希望在应用程序运行(用户可以在不同的活动之间移动),这个平均到最后,所以我不能清除它的onDestroy()为特定的活动。我需要能够将其清除,一旦应用程序即将退出。

I have an Activity that is keeping a running average of a few numbers, that I'm storing in a SharedPreference. I want this average to last while the app is running (the user can move between different activities) so I can't clear it on onDestroy() for that particular activity. I need to be able to clear it once the app is about to quit.

我怎样才能做到这一点?

How can I do this?

推荐答案

因此​​Android并没有真正有一个应用程序的概念被汉化。 Unfortunently没有什么同义于onTerminate()。有一些标准,通过它可以决定何时清除您的移动平均值?

So android doesn't really have a concept of an app being "finished". Unfortunently there is nothing synonymous to "onTerminate()". Is there some criteria by which you can decide when to clear your running average?