进行服务前景服务 [英] making a service a foreground service

查看:160
本文介绍了进行服务前景服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要做一个前台服务的服务。我的服务已经没有必要向用户传达。我已经看到了这个论坛最简单的例子是把这个code在服务...

I have a service that I want to make a Foreground service. My service has no need to communicate to the user. The simplest example I have seen in this forum is to put this code in the service...

    Notification notification = new Notification();
    startForeground(5481, notification);

我已经看到了使用通知生成器(NotificationCompat.Builder)的Commonsware书第606一个更复杂的例子。这个和其他实施例有,需要提供复杂的通知。我没有这个必要。

I have seen a much more complicated example in the Commonsware book pp 606 that uses a Notification Builder (NotificationCompat.Builder). This and other examples have a need to provide complex notifications. I don't have this need.

我的理解是,我的软件是可以接受的,我必须至少显示一个图标,使用户知道,我的服务正在运行,给用户的方式来取消它。此外,如果我的服务决定停止在它自己的图标应该消失。但仅此而已。这就是我需要做的。

I understand that, for my software to be acceptable, I must at a minimum display an icon that makes the user aware that my service is running and give the user a way to cancel it. Also If my service decides to stop on it's own, the icon should go away. But that's it. That's all I need to do.

什么我要补充上述tode来实现这一目标? 谢谢,加里

What would I have to add to the above tode to accomplish that? thanks, Gary

推荐答案

你读过​​运行的服务在前景

您的通知需要一个图标,这样它会显示出来。该系统将不显示没有图标的通知。

Your notification needs an icon so that it will show up. The system won't display notifications that don't have icons.

使用NotificationCompat.Builder的原因是:a)它保持兼容性跨平台和b)用它,它更容易创建简单的通知。您可以使用生成器来创建复杂的通知,但你可以用它来构建简单的人也是如此。

The reasons to use NotificationCompat.Builder are a) it maintains compatibility across platforms and b) with it, it's easier to create simple notifications. You can use Builder to create complex notifications, but you can use it to build simple ones as well.

这很难说,更不知道你想做什么。

It's hard to say more without knowing what you're trying to do.

这篇关于进行服务前景服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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