Note that there are some explanatory texts on larger screens.

plurals
  1. POShould i require a new token every time i launch my Android App?
    primarykey
    data
    text
    <p>I know that in Android as in iOS and WP7 (<a href="https://stackoverflow.com/questions/16422177/in-which-mobile-platforms-the-push-token-is-not-permanent">In which mobile platforms the “push token” is not permanent?)</a> the push token provided to the device <em>CAN</em> change.</p> <p>That means we should handle this by requiring a new token ,at least every time our application launches.</p> <p><em>However</em> , this comes to complete contradiction to what i 've found so far in googles tutorials.(I cant remember where exactly i 've found this code , but i am pretty sure it was provided by google) The code looks like this :</p> <pre><code> //registering for push GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); Log.i("****************","I just Registered!!"); } else { Log.i("****************","Already registered"); } </code></pre> <p>The code above will execute the <code>GCMRegistrar.register(this, SENDER_ID);</code> line only once , the first time that the application launches. But i guess this ir wrong right? Because if the token changes , there is not way that our application will see that as it requires a token only once..</p> <h2>EDIT</h2> <hr> <p>Actually i just found where exactly was that code. Take a look here : <a href="http://developer.android.com/google/gcm/gs.html" rel="nofollow noreferrer">Get Started Guide</a></p> <p>I am quoting :</p> <p><strong><em>In the onCreate() method, add the following code:</em></strong></p> <pre><code>GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { Log.v(TAG, "Already registered"); } </code></pre> <p>When you register the device , the <code>onRegistered(Context context, String regId):</code> function is called. About this function the tutorial says :</p> <p><strong>onRegistered(Context context, String regId):</strong> <em>Called after a registration intent is received, passes the registration ID assigned by GCM to that device/application pair as parameter. Typically, you should send the regid to your server so it can use it to send messages to this device.</em></p> <p>So it says that i should send this id to my server. But the code before showed us that this function will be called just once ! So what happens when the token changes? How am i going to refresh it , to my server ? I think i should run this function every time the app launches ...</p> <p>Am i missing something here? Is the code wrong? Any thought would be helpful :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload