Android的 - 实施startForeground的服务? [英] Android - implementing startForeground for a service?

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

问题描述

所以我不知道在哪里/如何实现此方法,使我的服务在前台运行。目前,我在另一个活动下开始了我的服务:

So I'm not sure where/how to implement this method to make my service run in the foreground. Currently I start my service by the following in another activity:

Intent i = new Intent(context, myService.class); 
context.startService(i);

然后在myServices的onCreate(),我尝试startForeground()...?

And then in myServices' onCreate() I try the startForeground()...?

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

所以,是的,我有点失落,并不能确定如何实现这一点。

So yeah I'm a bit lost and unsure of how to implement this.

推荐答案

我想通过完全填写通知启动这里是展示了如何使用 startForeground的样本项目()

I'd start by completely filling in the Notification. Here is a sample project demonstrating the use of startForeground().

这篇关于Android的 - 实施startForeground的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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