I've implemented Firebase in my app and I'm sending push with extra data. When my app is in foreground I'm handling data properly and showing my own notification, but I have a problem with fetching data, when Firebase shows Notification "automatically" when app was "homed" (not killed). According DOCS Activity
should get new Intent
with extras fulfilled with my values, instead app just get back to front, old state is restored.
Scenario:
Notification
WITHOUT calling onMessageReceived
(according to table in docs, it should?)Intent
is fulfilled with "original" extras used for open Activity
on topI have logs in onCreate
, onNewIntent
, onResume
(Activity
) and in onMessageReceived
(Service
), only onResume
is called, in which I'm printing extras like below:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
Object value = getIntent().getExtras().get(key);
Log.d("Activity onResume", "Key: " + key + " Value: " + value);
}
}
So I was looking for this answer and read the same. It has to be some where. I know this is a year old but they still haven't really made it clear. In the pendingActivity associated with the notification ( in my case it was MainActivity ) I added the following. Please note I was working through the Google Codelabs com.example.android.eggtimernotifications not that this was in the answers.
override fun onResume() {
super.onResume()
intent?.run {
val keys = this.extras?.keySet()
if (!keys.isNullOrEmpty()) {
keys.forEach { key ->
when (this.extras!![key]) {
is Long -> println("$key = ${this.getLongExtra(key, 0L)}")
is Int -> println("$key = ${this.getIntExtra(key, 0)}")
is String -> println("$key = ${this.getStringExtra(key)}")
is Boolean -> println("$key = ${this.getBooleanExtra(key, false)}")
else -> println("unkonwn Type")
}
}
}
}
}
This resulted in the following.
The data keys were cereal, from, milk and sugar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With