Closed musriabhijit closed 7 years ago
Thanks for this question!
Can you try moving
mMeteor.addCallback(this);
mMeteor.connect();
from outside the condition into the else
branch right before these lines, i.e. right after createInstance
?
That should help because it will only establish a new connection when there was no singleton instance available, previously.
if i use mMeteor.addCallback(this); mMeteor.connect(); in the else part the meteor is not calling onDataAdded , onConnect or onException in the the Activity class so can you guide me in this problem
You're right, sorry. Try moving only the mMeteor.connect();
call to the else
branch as described before. The mMeteor.addCallback(this);
call must be done from whatever Activity
or Fragment
you're trying to receive results in.
if i use mMeteor.connect(); in else part it is same i am not able to call the onDataAdded, onConnect, onException so my question is if i use mMeteor.connect() it will create the new connection or not
Did you do this?
if (MeteorSingleton.hasInstance()) {
mMeteor = MeteorSingleton.getInstance();
mMeteor.addCallback(this);
}
else {
MeteorSingleton.createInstance(this, "wss://example.com/websocket", new InMemoryDatabase());
mMeteor = MeteorSingleton.getInstance();
mMeteor.addCallback(this);
mMeteor.connect();
}
in Onstart of every activity i am writing like this
if (MeteorSingleton.hasInstance()) { mMeteor = MeteorSingleton.getInstance(); } else { MeteorSingleton.createInstance(this, "my socket connection ", new InMemoryDatabase()); mMeteor = MeteorSingleton.getInstance(); }
and in onConnect method i am making the subscribe
but at server side they are telling that you are making too many server connections so some times i am able to connect and some times i am not able to connect so what i am doing is the correct one or not if i am wrong please correct me