Title: Click the notification, service create a new activity, and activity create a new service
Tags: android;service
Question: Click the notification, service create a new activity, and activity create a new service?
Let me first describe my use case:
My App MainActivity "OnCreate" create a service that is "sticky".
In my service, I post multiple notifications when there are some notices. The notice will be there unless user enters the app and reads the notice. There is a checking of new notice in onStartCommand.
Pressing the notification will send a intent to open the MainActivity.
My problem is:
There is Service, MainActivity and a notice.
After some time, MainActivity is killed by system.
Click the notification recreate the mainActivity. mainActivity start a "new?" service. The "new?" service create a new notification. So I am seeing multiple instants of same notice message. This is wrong. What is the correct way to handle this case?


Here is another answer: Quick fix:
Before showing the notification, check whether or not the notification already exists there.
if(!notificationExists()){
showNotification;
Comment for this answer: For full implementation of this pseudo-code, please show the code where you have built and showed the notification.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:03/22/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><service>', 'Title': 'Click the notification, service create a new activity, and activity create a new service', 'ViewCount': 41, 'id': 22574752, 'user_AboutMe': '', 'user_AccountId': 2558328.0, 'user_DisplayName': 'manhon', 'user_Reputation': 683.0, 'user_Views': 141.0, 'user_id': 2219865.0}}