NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(description.getTitle())
.setAutoCancel(false);
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notificationCompat=builder.build();
notificationManager.notify(MY_ID,notificationCompat);
startForeground(MY_ID,notificationCompat);
使用上面的代码在后台运行服务。但是当活动关闭时,服务调用 onDestroy