Android - 为服务实现startForeground?

2024-05-07

所以我不确定在哪里/如何实现此方法以使我的服务在前台运行。目前我在另一项活动中通过以下方式开始我的服务:

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

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

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

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


我首先完全填写Notification. 这是一个示例项目 https://github.com/commonsguy/cw-omnibus/tree/v8.4/Notifications/Foreground演示使用startForeground().

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android - 为服务实现startForeground? 的相关文章

随机推荐