I would like to test FCM messages that are received when the app is in a terminated state. The problem is Android Studio loses connection after I kill the app. How could I connect back to Android Studio debugger on launch?
I found this old thread How to debug app when it's killed but dont know if we have such a function in Flutter?
android.os.Debug.waitForDebugger();
I need to be able to see the logger output on whats happening in the app.
2
Answers
It is not real debugging, but in case of an Android device, you can add
print
statements to your code where you handle FCM notifications, and run the app from terminal in release mode to test. This does not work with iOS, at least I could not make it work.Add for example the following:
Somewhere after FCM is initalized, use this to get the initial message (the one that was clicked by the user when the app was terminated and caused the app to start):
After this connect your phone to your computer, start you application from terminal with:
Now you can terminate the app. Note that the session in terminal will be still on.
Check the following scenarios:
If there is a notification while to app is terminated, you will see "onBackgroundMessage".
If the user clicks on the message while the app is terminated, you will see "initialMessage".
I suggest you using ADB. Just type this command in the shell and you will receive realtime logs of your app (even if it is in terminated state).