控制android状态栏图标

我试图对状态栏中的图标状态进行一点控制.我希望能够做到以下几点:

>保留图标
在状态栏中可见,只要很长时间
当应用程序正在运行时,即使用户选择清除状态栏.
>从状态栏中清除图标
如果应用程序退出,甚至(特别是)如果它被杀死了?我明白我可以在明确退出应用程序时删除它,但我想确保它在应用程序被杀死时消失.我不得不承认我还没试过.

我还没有得到一些关于这方面的好消息,虽然我看过似乎正在做这个的应用程序.

解决方法:

1)在status bar notifications上查看开发人员文档页面.另请注意,您需要查看FLAG_NO_CLEAR常量,这应该涵盖您的情况.

2)在应用程序被杀的情况下保持图标不一定是坏事,并且在某种程度上取决于应用程序的目的.特别是,如果你的应用程序进入后台然后被杀,leaving the icon has actually been noted to be expected behavior by one of Google’s engineers

Correct, onDestroy() is not called
when it is killed. This is the same
as activity — the kernel kills
processes when needed, not waiting for
the app.

The status bar is correctly keeping
the icon. The service will later be
restarted; it has not been stopped.

It is normal for background services
to be killed regularly. This is
intentional, because generally
background services are not something
the user is directly aware of, and
restarting their processes every now
and then avoids issues with such
services consuming increasing amounts
of RAM.

If your service is something the user
is actually aware of (such as music
playback), consider
Service.startForeground().

话虽这么说,图标应该可能会消失.其他具有持久性图标的应用程序(Meebo会想到)如果您使用任务管理器杀死它们将会清除.不过,我不确定这是否会在所有情况下发生.如果您的应用程序在OOM的后台被杀,那么您很可能无论如何都不想清除它.

上一篇:android通知setSmallIcon with level-list


下一篇:Android:如何正确隐藏系统UI