Android

个人Android学习总结


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, // &amp;quot;carplatform&amp;quot;, system.currenttimemillis()); // intent notificationintent = new intent(service, null); // pendingintent pendingintent = pendingintent.getactivity(service, 0, // notificationintent, 0); // notification.setlatesteventinfo(service, &amp;quot;carrecord&amp;quot;, &amp;quot;videorecord&amp;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>

页面列表

ITEM_HTML