控制Android的状态栏图标 [英] controlling the android status bar icon

查看:141
本文介绍了控制Android的状态栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想锻炼稍微控制在状态栏图标的状态。我希望能够做到以下几点:

I am trying to exercise a little control over the state of an icon in the status bar. I want to be able to do the following:

  1. 在保持图标 在状态栏可见,只要 随着应用程序正在运行,即使用户选择清除状态栏。
  2. 从状态栏中清除图标 如果应用程序退出,甚至(尤其是),如果它被杀死?我知道我可以删除它,当应用程序被明确地退出,但我想,以确保它消失了,如果应用程序被杀害。我不得不承认我没有尝试这样做呢。
  1. Keep the icon visible in the status bar, as long as the app is running, EVEN IF the user chooses to clear the status bar.
  2. Clear the icon from the status bar if the app is exited, even (especially) if it is killed? I realize I can remove it when the app is exited explicitly, but I want to make sure it goes away if the app is killed. I have to admit I have not tried this yet.

我一直没能得到这方面的一些好消息,虽然我已经看到,似乎这样的应用程序。

I have not been able to get some good info on this, although I have seen apps that appear to be doing this.

推荐答案

1)看看上的状态栏通知。另外请注意,你要看看 FLAG_NO_CLEAR 不变,其中应包括您的病情。

1) Take a look at the developer docs page on status bar notifications. Also note that you'll want to look at the FLAG_NO_CLEAR constant, which should cover your condition.

2)保持图标不一定是坏事在应用程序被杀害,并且一定程度上取决于应用程序的用途的情况。特别是,如果您的应用程序进入后台,然后就会被杀死,<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/48c951292af464fb/2b20c08cf36a178e?pli=1"相对=nofollow>留下的图标实际上已经指出,可以预料的行为由谷歌的工程师之一:

2) Keeping the icon isn't necessarily a bad thing in the case where the app is killed, and somewhat depends on the purpose of the app. In particular, if your app goes into the background and then gets killed, leaving the icon has actually been noted to be expected behavior by one of Google's engineers:

正确的,的onDestroy()不叫   当它被杀死。这是相同的   作为活动 - 内核杀死   流程需要的时候,不是在等待   该应用程序。

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.

这是正常的后台服务   定期死亡。这是   故意的,因为一般   后台服务是不是   用户是直接地了解并   重新启动他们的流程每一个现在   然后避免此类问题   服务消费增加量   的RAM。

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.

如果你的服务是值得用户   实际上知道(例如音乐   播放),可以考虑   Service.startForeground()。

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

这就是说,该图标可能应该无论如何消失。持续性的图标其他应用程序(Meebo的浮现在脑海)将清除,如果你杀了他们一个任务管理器了。我不能肯定,如果这种情况发生在所有情况下,虽然。如果你的应用程序获得该OOM死亡,而在后台,那么你很可能不会仍要将其清除。

That being said, the icon should probably disappear anyway. Other apps with persistent icons (Meebo comes to mind) will clear away if you kill them with a task manager. I'm not certain if this happens in all cases, though. If your app gets killed while in the background by the OOM, then you most likely won't want to clear it anyway.

这篇关于控制Android的状态栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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