how to check whether the activity was launched from notification or from the user click on home screen dashboard app icon in android. Is there any parameters that tells that this activity was launched due to user clicked on notification..
Asked
Active
Viewed 6,354 times
2 Answers
6
There already were several questions on this topic:
As of the home screen part, as far as I know there is no way to detect that.
However, you can detect whether your activity is launched from the notification icon:
When setting up your notification, you put an extra into it's PendingIntent
, say fromNotification: boolean
.
In your main activity's onCreate
method you check the intent's extras, and if (there are any and) the fromNotification
is among them with the value true
, than you know it has been invoked by clikcing on the notification icon.
-
For launch from home screen, see http://stackoverflow.com/questions/4789300/is-there-any-way-to-distinguish-between-an-android-activity-onresume-from-the-hom – Rajath Apr 28 '11 at 10:16
-
That's right, but the `onNewIntent` will be called from the notification's intent too (and every resume regardless to launchMode), if the application was not in the background and so got garbage collected. – rekaszeru Apr 28 '11 at 10:23
1
You can use startActivityForResult() when launching Activity from your App and then check if getCallingActivity() returns null
. If it does, your activity has been launched from notification.

sealskej
- 7,281
- 12
- 53
- 64