0

enter link description hereI create a custom layout for notification in android.I use remoteview for building notification and also add setOnClickPendingIntent() in some widgets of custom layout.But when user click on it the process in running but the notification setAutoCancel(true) not working.I attach some pics of my code.If anyone face this issue and resolve so you can help me.enter image description here

video link

Muhammad Asad
  • 694
  • 6
  • 10

1 Answers1

0

you are calling startForeground, so you are running some Service and this Notification is it's graphic representation on the screen. setting setAutoCancel(true) won't work for such notification, as it will live as long as Service is. You have to stop this service by calling stopForeground(true) (e.g. in onDestroy), then your sticked-to-service notification will disappear

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • but i need to use foreground service for represent the notification.I also stop the service when application terminate – Muhammad Asad Aug 11 '22 at 06:28
  • so you can't dismiss this `Notification`. if you want a `Notification`, which will disappear after click - it can't be same, which is representing `Service`, so you have show another (using `notificationManager.notify(ANOTHER_ID, notification)`) or at least modify look of this `Service`-related one – snachmsm Aug 11 '22 at 06:30
  • i remove a notification using notificationManager.cancel(1).notification remove and i also stop the service but the notification panel does not dismiss – Muhammad Asad Aug 11 '22 at 06:42
  • i attach a video in the question – Muhammad Asad Aug 11 '22 at 06:42
  • i edit my question you can see – Muhammad Asad Aug 11 '22 at 06:47
  • when you are showing notification using `startForeground` then you are dismissing it with [`stopForeground(true)`](https://developer.android.com/reference/android/app/Service#stopForeground(boolean)). show your code how and when you are trying to dismiss your notification. and NEVER EVER post code/text as screenshot, you are forcing other users to rewirtting lines instead of just copying, many people won't answer just because it's "too hard" to answer – snachmsm Aug 11 '22 at 07:56
  • i stop the forground service and notification remove.But issue is that the status bar slider does not move up. – Muhammad Asad Aug 11 '22 at 09:07
  • you haven't mentioned that you need any status bar moving... you've asked a question how to dismiss `Notification`, I gave you an answer. I you have any other problem - ask new question, describe well exact issue and post related code (as text!). good luck! – snachmsm Aug 11 '22 at 09:16