Android – 正确的通知方式和服务

我正在开发一个Android应用程序,它必须通过蓝牙保持连接并监听来电,如果它在前台运行。
当我得到蓝牙连接时保持服务正常运行,并在断开连接时停止服务,从而能够正常工作。 Service

 public class ConnectionService extends Service { private final int NOTIFICATION_ID = 327; @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public IBinder onBind(Intent intent) { throw new UnsupportedOperationException("Not yet implemented"); } @Override public void onCreate() { //Creates notification Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Title") .setContentIntent(pendingIntent).build(); //Makes service run in foreground startForeground(NOTIFICATION_ID, notification); super.onCreate(); } @Override public void onDestroy() { stopForeground(true); super.onDestroy(); } } 

我的问题是: 考虑通知如何工作的变化,我真的不明白它是如何工作的,它是如何工作的,这是创建通知的正确方法?
而且,考虑到我想用这个服务得到什么,你有什么评论是好还是坏?

谢谢大家。 *所提供的代码是Java,但现在我正在与Kotlin合作,所以这两种语言都被接受。