一.什么是前台Service
希望能够让Service显示在通知栏里,不被进程杀掉
二.设置前台Service
@Override
public IBinder onBind(Intent intent) {
//设置为前台服务
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("播放音乐中..").setContentText("haha")
.setWhen(System.currentTimeMillis()).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
Notification notifation = builder.getNotification();
startForeground(2, notifation);
return mBinder;
}
@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
}