Initially my app is closed and when I receive a new message from GCM push service, I am starting a new activity from onMessage() in my class which extends GCMIntentService
. I want to use the debugger to check some errors. My question is that is there a way to Debug the app when started from the Push Notification?
To clear a bit more, I have a BroadcastReceiver
and a service attached to it. Even is the app is closed, it receives the broadcast and starts an activity based on the message received. It is possible that the app receives the broadcast when it is not open. Now, when the app is open and I get a Push Message then I can debug it. But the problem is when when app is closed and it receives the broadcast, then how to debug it?
The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app.
If your target platform is Android, you can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications.
The app publisher composes a manual message through a message composer user interface. Alternatively, the publisher sets up an automated message to be sent via the API. The publisher defines the audience to whom the push notification will be sent.
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
/*
the following line will halt the app here
to give you time to attach the debugger
*/
android.os.Debug.waitForDebugger();
/*
then you can put a breakpoint on any line
after that, like here:
*/
Log.d("onMessageReceived", "From: " + remoteMessage.getFrom());
...
}
You can put the line android.os.Debug.waitForDebugger();
anywhere in your code where you want to stop execution and attach the debugger. Just remember to remove it when you're done debugging.
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