I have an issue in callback interface initialization.
I have to pass the push notification data to my MainActivity (HomeActivity).
So, I have a listener (interface object) as below :
class FirebaseMessageReceiver : FirebaseMessagingService() {
...
lateinit var pushNotificationArrivedListener:PushNotificationListener
...
}
Inside the method :
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (this::pushNotificationArrivedListener.isInitialized && pushNotificationArrivedListener != null) {
pushNotificationArrivedListener.onPushNotificationArrived(firmwareObj)
}
}
Where, In same class the interface is created as below :
interface PushNotificationListener {
fun onPushNotificationArrived(firmwareObj:FirmwarePushNotification)
}
Overriding it in HomeActivity as below :
override fun onPushNotificationArrived(firmwareObj: FirmwarePushNotification) {
Log.e("&&&&& ","&&&&& onPushNotificationArrived")
}
Implementing and Initiating it as below in HomeActivity :
class HomeActivity : AppActivity(),FirebaseMessageReceiver.PushNotificationListener {
and inside onCreate() initializing the interface as below :
firebaseMessageReceiver.initializePushNotificationListener(this)
WHERE,
firebaseMessageReceiver is initialized in App.kt class as below :
var firebaseMessageReceiver: FirebaseMessageReceiver = FirebaseMessageReceiver()
Everything is looks correct, But listener is not getting initialized.. i.e. below if condition is not satisfying :
if (this::pushNotificationArrivedListener.isInitialized && pushNotificationArrivedListener != null) {
What might be the issue?
EDIT Below is the method also inside class :
fun initializePushNotificationListener(pushNotificationArrivedListener: PushNotificationListener) {
this.pushNotificationArrivedListener = pushNotificationArrivedListener
}