Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

android - Should applications call gcm.register() every seven days to ensure valid registration IDs?

The client-side code in the GCM example on the Android dev site defaults to calling gcm.register(SENDER_ID); after every seven days by checking if registration has expired using the following function:

public static final long REGISTRATION_EXPIRY_TIME_MS = 1000 * 3600 * 24 * 7;

/**
 * Checks if the registration has expired.
 *
 * To avoid the scenario where the device sends the registration to the
 * server but the server loses it, the app developer may choose to re-register
 * after REGISTRATION_EXPIRY_TIME_MS.
 *
 * @return true if the registration has expired.
 */
private boolean isRegistrationExpired() {
    final SharedPreferences prefs = getGCMPreferences(context);
    // checks if the information is not stale
    long expirationTime =
            prefs.getLong(PROPERTY_ON_SERVER_EXPIRATION_TIME, -1);
    return System.currentTimeMillis() > expirationTime;
}

The comment above the function implies that this is used to "avoid the scenario where the device sends the registration to the server but the server loses it. Is this suggesting that our servers (not the GCM servers) may lose the registration id? Or is this because the registration ID could become invalid on the GCM side of things? It appears that this is possible as per the following paragraph in the GCM Advanced Topics Page:

Similarly, you should not save the registration ID when an application is backed up. This is because the registration ID could become invalid by the time the application is restored, which would put the application in an invalid state (that is, the application thinks it is registered, but the server and CM do not store that registration ID anymore—thus the application will not get more messages).

Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...