I have implemented notification within service. Notification works fine. But in the case when app is running already and I clicked on android status bar notification it launches new copy of my app. which is obviously wrong. It should be if user click on status bar notification, should start app if app is not running already otherwise it should opens other activity (message activity in my case). I tried many suggestions provided in similar type of problem posted here but I didn't get solution in my case.
3 Answers
How about setting the launchMode to SingleInstance in the app's manifest.
There's also the trick I picked up on here about having a special NotificatonActivity that the notification calls:
Notification to restore a task rather than a specific activity?

- 1
- 1

- 1,151
- 1
- 7
- 17
Here i manage to escape out from this problem. First of all i defined Boolean variable in entry activity or class which extends application. i set attribute to that variable true when application runs and false when application exit. and i check that Boolean variable to which activity to open. in my case this solve the problem. may be it helps to your case too.bt scenario may be different. good luck

- 1,662
- 14
- 38
Using a boolean is not a good solution for this problem. For more info please look at the life time of the application. Instead you should change your launchMode to singleTask or singleInstance in your target activity and receive your intent from onNewIntent() method of that activity.
But be aware, if you call super.onNewIntent(intent); then a second instance of the activity will be created. So don't call that and do whatever you want with your intent.

- 1,694
- 19
- 26