I have Firebase
implemented at application level to receive push messages. In the library project, I have a BroadcastReceiver
to intercept push messages. I want to build notification from the library and not from the application.
Incase of app in foreground state, when I create a Pending intent, the MainActivity context available at the app level is passed in the pending intent, upon which if the notification is tapped, I am redirected to MainActivity. Now if the app is in killed state and push message is received, my broadcast receiver in the library intercepts the incoming message, but not able to create notification because the MainActivity context is null as the MainActivity at app level is not available in the stack trace. Can anyone assist how to achieve this?
Below is my code :
val mIntent = Intent(applicationContext,activityContext::class.java)
val pendingIntent = PendingIntent.getActivity(applicationContext, System.currentTimeMillis().toInt(),
mIntent,PendingIntent.FLAG_UPDATE_CURRENT)
where, activityContext in the Intent
is the context of MainActivity received inside the library project from app level.
When app is in foreground state, activityContext is available and notification gets generated. But when app is in killed state, activityContext remains null leading to failure in building the notification.