how to check whether the activity was launched from notification or from the user click on home screen 开发者_如何学Pythondashboard app icon in android. Is there any parameters that tells that this activity was launched due to user clicked on notification..
There already were several questions on this topic:
- detecting application launch from home or history
- Determine if app was launched from home screen?
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.
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.
精彩评论