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

问题描述

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

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

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

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


解决方案

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

:-)

Probably not.

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.

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).

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

09-13 22:47