Service设置为前台服务
<pre><code>### service设置为前台服务
1、在oncreate()中start startforegroundservice() ;
2、在ondestory()中stop stopforegroundservice() ;
public class foregroundserviceutil {
private static final int ongoing_notification = 0x112;
public static void startforegroundservice(service service) {
// notification notification = new notification(r.drawable.ic_launcher1,
// &quot;carplatform&quot;, system.currenttimemillis());
// intent notificationintent = new intent(service, null);
// pendingintent pendingintent = pendingintent.getactivity(service, 0,
// notificationintent, 0);
// notification.setlatesteventinfo(service, &quot;carrecord&quot;, &quot;videorecord&quot;,
// pendingintent);
notification notification = new notification(); //创建一个空通知
notification.flags |= notification.flag_no_clear;
service.startforeground(ongoing_notification, notification);
}
public static void stopforegroundservice(service service) {
service.stopforeground(true);
}
}</code></pre>