destroyInstance() breaks if not connected
If it is already disconnected when calling MeteorSingleton.destroyInstance(), it will throw java.lang.IllegalStateException: You must have called the 'connect' method before you can disconnect again.
That means every time if I need to destroy the instance when disconnected, I have to reestablish the connection, just for destroyinstance() to disconnect it, which sounds a bit strange to me.
public synchronized static void destroyInstance() {
if (mInstance == null) {
throw new IllegalStateException("Please call 'createInstance(...)' first");
}
mInstance.disconnect();
mInstance.removeCallbacks();
mInstance = null;
}
Could the IllegalStateException be handled internally within destroyinstance(), or is it possible to have a way to simply set minstance = null? Thanks!
Thank you!
You're right, we should probably just wrap the statement
mInstance.disconnect();
in a try block and ignore the IllegalStateException like this:
try {
mInstance.disconnect();
}
catch (IllegalStateException ignored) {}
That seems to match the goal of the MeteorSingleton class (which is simple management of the instance) and that of the destroyInstance method (which is to ensure that the instance is both disconnected and destroyed). Do you agree?
Yes, I agree with that.