Jitesh
Jitesh

Reputation: 269

how to check whether the activity was launched from notification or from the user click on home screen dashboard app icon in android

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..

Upvotes: 2

Views: 6528

Answers (2)

sealskej
sealskej

Reputation: 7421

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.

Upvotes: 1

rekaszeru
rekaszeru

Reputation: 19220

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.

Upvotes: 6

Related Questions