Android应用程序对象的生命周期
我找不到Application的对象(延长Application)生命周期。 例如,如果我有一个通过 Alarm 调用的广播接收器,会发生什么情况。会调用应用程序中的方法吗?或者一切都独立于应用程序? 如果我在应用程序中实例化了一个 datahelper 并且我从广播接收器调用它,它是否可用? 当应用程序对象被销毁时,它的生命周期是哪个?使用闹钟时什么时候调用它?当 Activity 不在应用程序对象的前台时会发生什么? 提前致谢。吉列尔莫.
I can't find the Application's object (extend Application) life cycle.
For example, what happens if I have a broadcast receiver which is called through Alarm. Will methods in Application being called? Or is everything independent from the Application?
If I have a datahelper instantiated in the Application and I call it from broadcast receiver, will it available?
Which is the Application object life cycle, when it is destroyed? when is it called when using Alarms? What happens when the activity is not in foreground with the Application object?
Thanks in advance. Guillermo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样看:在其他一切之前,有
应用程序
。它是在您的BroadcastReceiver
之前、您的Activity
实例之前、您的Service
实例之前创建的。前景。当您的所有Activity
实例消失、您不再使用BroadcastReceiver
以及您的Service
实例终止时,应用程序将终止。不能保证它会被杀死,但当操作系统决定您的应用程序必须终止时,这是最后一件事。Look at it this way: before everything else, there is
Application
. It is created before yourBroadcastReceiver
, before yourActivity
instances, before yourService
instances, etc. It doesn't matter whether anything is in the foreground. The application will be terminated when all of yourActivity
instances are gone, when you're out of yourBroadcastReceiver
and once yourService
instances are terminated. There's no guarantee that it will be killed, but it is the last thing to go when the OS decided that your app must die.