MaxK
MaxK

Reputation: 437

GCM demo won't accept messages on server & app restart

I followed the demo client/server tutorial that Android docs have provided (http://developer.android.com/google/gcm/demo.html). Everything worked exactly as advertised when I first tried it out. The servlet first came up with "No devices registered!" screen, then started the demo app on my device and I was able to send the demo messages to the device just fine.

Then I shutdown my Tomcat server that deployed the gcm-demo war and closed the demo client app on my device (which is not an emulator, Nexus 7). I started the tomcat server back up, I see it did deploy the gcm-demo war as expected however when I go to the URL of the servlet (the one that originally said "No devices registered!") it now says that No devices are registered. I opened up the app on my device and it says that device is already registered on server. Why is the servlet not seeing my device that IS registered?

I appreciate any help, thank you.

Upvotes: 0

Views: 505

Answers (2)

Deepak Bala
Deepak Bala

Reputation: 11185

@NickT is right. If you want persistent storage of regIds you can back it up with a java.util.Properties that stores the data into a properties file or write a simple file store yourself.

Reset the state of your client app by deleting the cache or re-installing the app.

Upvotes: 1

NickT
NickT

Reputation: 23873

I didn't take the Tomcat/servlet approach myself, opting for an Apache/PHP/MySQL way instead, so I've no direct experience, but reading the sample code I see as the comment in the server's Datastore.java, this:

/**
 * Simple implementation of a data store using standard Java collections.
 * <p>
 * This class is thread-safe but not persistent (it will lost the data when the
 * app is restarted) - it is meant just as an example.
 */

So basically when you restart Tomcat it's forgotten your regId.

Upvotes: 3

Related Questions