0

I have an notification that works fine yesterday, the notification not appears and I don't remember I had touched the code.. that notification must be appears when I get the desired value and must open a pop up dialog we user touch it.

can anyone help please?

the notification code - in side service-:

Intent notifyIntent = new Intent(context.getApplicationContext(), PopUp.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //how I tried to pass data notifyIntent.putExtra("text1", text1); notifyIntent.putExtra("text2", text2); PendingIntent pIntent = PendingIntent.getActivity(context, 1, notifyIntent, 0); // build notification // the addAction re-use the same intent to keep the example short Notification n = new NotificationCompat.Builder(context,CHANNEL_ID2) .setContentTitle("check this") .setSmallIcon(R.drawable.ic_delete) .setContentIntent(pIntent) .build(); NotificationManager notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, n); 

I'm using android studio emulator API 30 in the same service class I have a Notification and it is appearing to indicate that the service is working in the background, except the Notification that I but its code above it is not working suddenly

I don't know what is the problem, please help

1 Answer 1

1

When Issuing the notification with notify the notificationId must be a unique int for each notification. Update your code to include a random unique notificationId

see below

//you can use the timestamp int notificationId = Integer.parseInt(String.valueOf(System.currentTimeMillis())); NotificationManager notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE); // notificationId is a unique int for each notification that you must define notificationManager.notify(notificationId, n); 

Android Create a Notification

Sign up to request clarification or add additional context in comments.

1 Comment

I just use a createNotificationChannel2() as I have createNotificationChannel() for the service notification I it is working now! by using your method how will enhance or improve my code? sorry if my question considered silly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.