Closed proft closed 7 years ago
That looks like you are at least establishing a new connection every time you open a new Activity
. You should call the connect
method on a Meteor
instance only once. But you are doing it in onActivityCreated
which means that it's done more often.
Try removing that meteor.connect()
call in onActivityCreated
and adding it as m.connect()
at the end of your catch
block in getMeteor
instead.
Thank you for response!
I see you point of view but ... I just open emulator and wait (emulator and activity is in focus). No Activity
recreation. So method onActivityCreated
doesn't call again.
I can't add m.connect()
at the end of catch
block in getMeteor
because getMeteor
is in utility class. All actions occur in ListFragment
and method like onConnect
, onDisconnect
, onDestroy
are in this ListFragment
.
So I have one utility method with MeteorSingleton
and many fragments that use meteor object from NetworkUtil
and in this fragments I created methods for onConnect
, onDisconnect
, onDestroy
.
To my surprise each ListFragment
call onConnect
on every 10-15 secs when this fragment is in focus.
After
MeteorSingleton.createInstance(context, "ws://server.com/websocket", new InMemoryDatabase());
m = MeteorSingleton.getInstance();
can you add
m.setLoggingEnabled(true);
and check if there's some helpful information printed to the console then?
Reading your explanation, I still don't understand why you can't move the call to the connect
method as explained. Did you actually try this?
I rearranged connect
method and I got what I want :)
By the way, don't know about setLoggingEnabled
.
Thanks for your patience! :)
Hello!
Interesting stuff! Preface: I have Meteor app and Android app.
My
onConnect
methodIn log I see
CONNECTED!
every 10-15 seconds. Why? There is no new data, no problem with network connection ...I get Meteor instance as following
In fragment
In
NetworkUtil
To my mind, it should be only one
CONNECTED!
. Am I right?