title: How to send push notification just only to UID User in Firebase?
body: <p>I'm just using firebase, now I've managed to create user authentication and have a few push notification questions in the firebase.</p>
  
  <p>Before I followed the tutorial <a href="https://www.youtube.com/watch?v=trx5beU4g6E" rel="nofollow noreferrer">here</a>, and it worked I was very happy. But apparently after I logout and try push notification, I still still receive the notification.</p>
  
  <p>So my question is also pretty much about push notifications, namely:</p>
  
  <ol>
  <li>How to make the notification only enter when I'm logged in?</li>
  <li>How do I target the notification with the registered UID only?</li>
  <li>Is it necessary to make notifications from firebase, so it can't be as straightforward as an automatic chat application?</li>
  </ol>
  
  <p>Here's the code I've made:</p>
  
  <p><strong>MyFirebaseInstanceldService.java</strong></p>
  
  <pre><code>public class MyFirebaseInstanceldService extends FirebaseInstanceIdService {
  
  
      @Override
      public void onTokenRefresh() {
          // Get updated InstanceID token.
          String refreshedToken = FirebaseInstanceId.getInstance().getToken();
  
          // If you want to send messages to this application instance or
          // manage this apps subscriptions on the server side, send the
          // Instance ID token to your app server.
          sendRegistrationToServer(refreshedToken);
      }
  
      private void sendRegistrationToServer(String refreshedToken) {
  
      }
  }
  </code></pre>
  
  <p><strong>MyFirebaseMessaginService.java</strong></p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
      public MyFirebaseMessagingService() {
      }
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          super.onMessageReceived(remoteMessage);
  
          sendNotification(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
      }
  
      private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, HotelManagementActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                  PendingIntent.FLAG_ONE_SHOT);
  
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
          notificationBuilder.setSmallIcon(R.drawable.rotarylogo);
          notificationBuilder.setContentTitle("Rotary Barcode");
          notificationBuilder.setContentText(messageBody);
          notificationBuilder.setAutoCancel(true);
          notificationBuilder.setSound(defaultSoundUri);
          notificationBuilder.setContentIntent(pendingIntent);
  
  
          NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
          assert notificationManager != null;
          notificationManager.notify(0, notificationBuilder.build());
      }
  }
  </code></pre>
  
  <p>If there is anything I still need to add, just say for the other code. I thank you very much for wanting to help me who is still a beginner.</p>