当firebase推送的时候,是分当前应用在前后台两种情况的。当应用在前台的时候,消息到来的时候会响应onMessageReceived函数,你就可以在里面想怎么处理就怎么处理了。当应用在后台或者被杀掉的时候,这个函数是不会响应的,它会直接吧参数发送到启动的Activity中,以下是google的文档说明:
Handle messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload. In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
处理方式:在后台的情况下你需要在应用的主Activity的onCreate方法中调用getIntent.getExtra()方法才能拿到推送到的参数