Ad

Detect Activity Launch

I am using an external library in our project. That library showing notification. On tapping that notification starts activity in the library.

I want to detect that activity launch from push notification to track some analytics data.

Is there any way to detect those notification taps or activity launch?

Ad

Answer

As far as I understand you activity is already launched on notification tap. For detecting activity launch you can use ActivityLifecycleCallbacks. In such case you will need to override onActivityCreated/onActivityStarted which includes created/started activity as argument. You can inject analytics component inside and send events about launched activities.

class AppLifecycleCallbacks : ActivityLifecycleCallbacks {
    override fun onActivityStarted(activity: Activity) {
        if (activity is MyActivity) {
            //...
        }
    }

    //...
}
Ad
source: stackoverflow.com
Ad