Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Remove registrationId and senderId from sharedPrefs on unregister #294

Closed
kentmw opened this issue Nov 2, 2015 · 3 comments
Closed

Remove registrationId and senderId from sharedPrefs on unregister #294

kentmw opened this issue Nov 2, 2015 · 3 comments

Comments

@kentmw
Copy link

kentmw commented Nov 2, 2015

I'm suggesting we add the following to PushPlugin.java at line 127.

SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.remove(REGISTRATION_ID);
editor.remove(SENDER_ID);
editor.commit();

Without this, if you unregister and then initialize, it will return an old registrationId not associated with any instanceId. You'll be in a weird state that the application will think it's registered but it's not. That's due to this logical block on register:

if ("".equals(savedSenderID) && "".equals(savedRegID)) {
  token = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);
}
 // new sender ID, re-register
else if (!savedSenderID.equals(senderID)) {
  token = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);
}
// use the saved one
else {
  token = sharedPref.getString(REGISTRATION_ID, "");
}

I'm adding this to my fork because some strange reason, I'm getting an emtpy string "" for a registrationId upon initialization of the plugin (See #295). Regardless, my work around is to unregister if I didn't receive an actual registrationId and then re-register. However, without the code above, it will just fallback to old, outdated registrationId - in my case an empty string.

@macdonst
Copy link
Member

macdonst commented Nov 2, 2015

@kentmw it's a duplicate of #291 which I'm already working on.

@macdonst macdonst closed this as completed Nov 2, 2015
@kentmw
Copy link
Author

kentmw commented Nov 2, 2015

@macdonst, seriously just saw that issue moments after typing all this up...

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants