Do not display notification after seeing that once

Hi, I do not want to show any notification service in the status bar if I once saw one notification service. For example, I show people who are more than 20 km away from my location. Some people are displayed. When I saw it once, then automatically the icon in the status bar is not displayed. For this, give me some suggestions. Thanks in advance.

+3
source share
2 answers

If your question is about preventing the display of notifications after the user clears one of your previous notifications, you probably need to maintain your own data structure in order to control this.

The idea is this:

  • -// , , .
  • , hashtable – , . .
  • -.
  • - .

Notification.deleteIntent.

. , , . , .

+1

:

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean used = sp.getBoolean("notif_used", false);

if ( used )
 return;
else {
 /* show the notification */
 Editor editor = getSharedPreferences().edit();
 editor.putBoolean("notif_used", true);
 editor.commit();
}
+1

Source: https://habr.com/ru/post/1744730/


All Articles