当我的应用程序的过程中死亡 [英] When does my app's process die

查看:127
本文介绍了当我的应用程序的过程中死亡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报警的应用程序,用户可以设置多个闹钟。当警报响起(使用AlarmManager和一个BroadcastReceiver)的应用程序只显示一个通知。

我的应用程序可能无法在前台的很长一段时间所以不会有UI线程运行。

我的问题是,当警报响起,并显示一个通知,我的应用程序的code的一部分被执行(该广播接收器和通知创建)。接下来发生什么?是我的应用程序的过程当即毙命?是否继续留在部分闲置状态,直到Android的决定杀了它?

(这是所有与约持续通知的ID。当我的应用程序是不是一个问题(http://stackoverflow.com/questions/11376294/do-i-need-to-persist-my-notification-ids)在前台运行和两个报警分开走了一分钟,我通知的ID存储在一个静态的ArrayList,在第二个通知创造看来我的通知创造者类仍占据第一通知的ID ArrayList中使用调试器。这表明这个过程生活在第一和第二报警器响了的。)


解决方案

  

接下来会发生什么?


由于你的头像,你有一个点O'茶。也许一品脱,根据每天和饮料preference的时间。

: - )


  

是我的应用程序的过程当即毙命?


大概没有。


  

是否保持在部分闲置状态,直到Android的决定杀了它?


是的。 Android的进程终止时,它需要的RAM启动其他进程。如果过程没有运行的组件,这将是进程列表上相对高的将被终止。所以,你的过程可能不是生活非常长,但有你的广播接收器结束与被终止的进程之间没有直接的因果关系。


  

在我的应用程序是不是在前台运行和两个报警分开熄灭一分钟,我存储在一个静态的ArrayList通知的ID。使用第二通知单的创建,调试器似乎我通知创造者类仍占据第一通知的ArrayList中的ID。这表明,生活过程中,第一和第二报警器响了的。


由于只有闹铃的分钟,这是合理的,你的过程可能会坚持围绕,但不能保证。当然,跑警报每分钟不断地不太可能让你很受欢迎,所以一定要确保用户对这种行为(例如,可以完全阻止你的应用程序,可以修改轮询周期)一些控制。

I have an alarm application where users can set multiple alarms. When an alarm goes off (using AlarmManager and a BroadcastReceiver) the app simply displays a Notification.

My app may not be in the foreground for long periods of time so there will be no UI thread running.

My question is, when an alarm goes off and a Notification is displayed, part of my app's code is executed (the BroadcastReceiver and Notification creation). What happens next? Is my app's process immediately killed? Does it remain in some idle state until Android decides to kill it?

(This is all related to another question (http://stackoverflow.com/questions/11376294/do-i-need-to-persist-my-notification-ids) about persisting Notification IDs. When my app is not running in the foreground and two alarms go off a minute apart, I store the Notification IDs in a static ArrayList. Using the debugger on the second Notification creation it seems that my Notification creator class still holds the first Notification's ID in the ArrayList. This suggests that the process lives between the first and second alarm going off.)

解决方案

What happens next?

Given your avatar, you have a spot o' tea. Or perhaps a pint, depending on time of day and beverage preference.

:-)

Is my app's process immediately killed?

Probably not.

Does it remain in some idle state until Android decides to kill it?

Yes. Android terminates processes when it needs RAM to start up other processes. If your process has no running components, it will be relatively high on the list of processes to be terminated. So, your process may not live terribly long, but there is no immediate causal relationship between your BroadcastReceiver ending and the process being terminated.

When my app is not running in the foreground and two alarms go off a minute apart, I store the Notification IDs in a static ArrayList. Using the debugger on the second Notification creation it seems that my Notification creator class still holds the first Notification's ID in the ArrayList. This suggests that the process lives between the first and second alarm going off.

With only a minute between alarms, it is reasonable that your process might stick around, but that is not guaranteed. Of course, running an alarm every minute constantly is unlikely to make you very popular, so make sure the user has some control over this behavior (e.g., can stop your app outright, can modify the polling period).

这篇关于当我的应用程序的过程中死亡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆