Pinki
Pinki

Reputation: 21929

don't display the notification after seeing that once

Hi I don't want to display the any notification service in status bar if i saw one notification service once .For example i am displaying persons who are exceeding the 20 km distance from my location .some persons are displayed.when i saw it once then automatically the icon in the status bar is don't displayed.For this one give me some suggestions .Thanks in advance.

Upvotes: 3

Views: 450

Answers (2)

Macarse
Macarse

Reputation: 93143

I do this:

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();
}

Upvotes: 1

Roman Nurik
Roman Nurik

Reputation: 29745

If your question is about preventing the display of notifications once the user clears one of your previous notifications, you'll probably need to maintain your own data structure to monitor this.

The idea is:

  • Store a hashtable/hashset/other data structure indicating which notifications the user has already seen.
  • Before showing a notification, check the hashtable – if the notification is in there, don't show it. Otherwise, show it.
  • When showing a notification, add it to the hashtable.
  • Flush the hashtable every so often.

You might also want to look into Notification.deleteIntent.

Caution: Before doing this, consider if this is really necessary. It might be sufficient to simply collapse visible notifications by reusing notification IDs.

Upvotes: 1

Related Questions