Android应用程序在退出事件 [英] Android Application On Exit Event
问题描述
我需要在应用程序退出处理一些帮助。 我的应用程序有多个活动说: - EntryAct,ACT1,ACT2 .... Act10
I need some help in application exit handling. My application has multiple Activity say : - EntryAct, Act1, Act2 .... Act10.
当用户presses家在任何这些活动的关键,我需要做一些标志设置。
When user presses home key on any of these Activities, I need to do some flag setting.
在每个应用程序的活动搬运home键是不可能的! 谁能告诉如何能做到这一点?
Handling home key in every application Activity is not possible! Can someone tell how this can be achieved?
不能更改将OnPause,的onStop或全部活动OnDestory ACT1 ... Act10什么。 : - (
Can't change anything in OnPause,OnStop or OnDestory of all activities Act1... Act10. :-(
推荐答案
您的问题,可如果您使用自定义应用程序级的解决。说喜欢
your issue can be solved if you use a custom Application class. say like
public class MyApp extends android.app.Application
{
}
和这里面的放,你想在你的应用程序的任何地方称为你的code。
and inside this put your code that you want to be called anywhere in your app.
现在只有你需要获取应用程序对象的活动
像这样
Now only you require to get the application object in your Activity
like this
MyApp app = (MyApp) getApplication();
app.setUpBeforeClosingApp();
,你可以在里面把这个间隔的onDestroy()
活动,并从这里code处理闭合动作就可以实现了。
and you can put this inside every onDestroy()
of Activity and from here code handling before closing actions can be achieved.
这篇关于Android应用程序在退出事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!