delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

how to subscribe data from server #76

Closed daniel6435 closed 8 years ago

daniel6435 commented 8 years ago

Hi,

i like to subscribe data from server to android, is it possible? how can i do?

String subscriptionId = mMeteor.subscribe("publicMessages");

Thanks

cristianhoyos66-zz commented 8 years ago

Yes, you can do it with that and consequently adding a callback using this: mMeteor.addCallback(this); to receive data from publish on the server.

You can get more info here: #44

ocram commented 8 years ago

@cristianhoyos66 Thank you so much for helping out :)

@daniel6435 Is there anything left that you haven't understood after reading @cristianhoyos66's explanation and after having read the issue he referenced?

romaluca commented 8 years ago

Hi, is possible changes parameter in the subscribe? i need to do something like this: http://www.meteorpedia.com/read/Infinite_Scrolling So i have to implement this:

Deps.autorun(function() {
    Meteor.subscribe('items', Session.get('itemsLimit'));
  });

Is possible with android-ddp recall a subscript with a different parameter (in my case the parameter is the limit of items)? Thanks!

ocram commented 8 years ago

@romaluca Well, as written in the README, the following is how to pass a parameter to a subscription:

myMeteor.subscribe("my-subscription", new Object[] { myLimit });

Since you subscribe once, you can't pass changing values, can you? As far as I can see, the only way to change the limit is to subscribe again with a different value.

daniel6435 commented 8 years ago

Thanks @mwaclawek and @cristianhoyos66 for answer my question, i already get the subscribed result from my collection, but is there possible to know the size of my collection(how many list of data in my collection)?

ocram commented 8 years ago

@romaluca If you wanted to know whether the subscription will automatically re-run as soon as it notices that the parameter's value has changed, that's not possible. Sorry! This kind of reactivity is only available in the official JavaScript client of Meteor.

@daniel6435 If you want to know the size, you either have to wait until all documents have been received (the SubscribeListener of your subscribe call will be fired) and then count how many documents you have received. Or you have to define a method on your server, e.g. countMyDocuments that returns the count directly from the database. On Android, you could then call that method.

daniel6435 commented 8 years ago

@mwaclawek how do i know when it received all document?

ocram commented 8 years ago

@daniel6435 You can find an example here: https://github.com/delight-im/Android-DDP/issues/65