-
-
Notifications
You must be signed in to change notification settings - Fork 32
Live query doesn't unsubscribed. #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, Thanks for trying LiveQuery. I'm not sure how the equals method is implemented on a ParseQuery. I suggest you to keep a reference to your ParseQuery instance and pass the same when unsubscribing. query = ParseQuery.getQuery("Message");
Client.subscribe(query);
Client.unsubscribe(query); Thanks |
By the way, when unsubscribing, you can only pass the query. The SubscriptionHandling is optional. You have also the method with only the query. Every subscribe method will give you a SubscriptionHandling that is you hook to that subscription. You should keep it like you do in the snipper if code. messageLQ.handleUnsubscribe(query -> {
messageLQ = null;
// this code doesn't worked
} Should be done when subscribing, not unsubscribing: private SubscriptionHandling<Message> messagesLQ;
private ParseQuery<Message> query;
public void onResume(){
super.onResume();
query = ParseQuery.getQuery("Message");
messageLQ = Application.getInstance().getLiveQueryClient().subscribe(query);
messageLQ.handleEvent(Event.CREATE, (query, object) -> {
// Handle create if wanted
}).handleUnsubscribe(query -> {
messageLQ = null;
// unsubscribed! yay
});
}
public void onPause(){
super.onPause();
Application.getInstance().getLiveQueryClient().unsubscribe(query);
// OR Application.getInstance().getLiveQueryClient().unsubscribe(query, messageLQ);
} |
So, I tried a different ways to unsubscribe query. In fact, unsubscribe callback is not important for me. Important that when I call Client.unsubscribe(query, handling), subscription callback continued to work. It's not good. General problem is when I start new activity, new subscription (or thread or socket, not important) created, and subscription callback executed several times. What do you say to that? |
Could you please repost update code of your solution. That will help debugging. Thanks. |
May be I don't initialise something? I'm not trying to blame something. I'm really need help. I'm shocked. |
We are using parse live query at my job since we developed it and it is working great. Like you said, maybe it is a setup issue. Can you repost your up-to-date solution, it will help me debugging you. Thanks |
|
thank you |
I understood what the error was. In unsubscribe method I passed a new instance of the same query. In implementing the live query client method "unsubscribe" developer use non-override "equals" (==) which only check links, not body. In result, I had to store all parse query as a singleton. I think, it's not good way, "equals" for complex objects should be override. |
|
@Deamond12333 Yes I'm happy that found that :). But this is pretty much what I explained you in that previous answer #91 (comment) I'm not sure about all the reason of not implementing a proper equals on a query, but for now you should keep a reference to it, not necessary as a singleton, depending how your project is built. In our application we have one classe to manage the query and handle all the answer. That managing class can be a singleton OR can only live for the duration of your activity lifecycle. Up to you... But I think it is good pattern to keep a reference to the query.. Thanks |
Backend:
Parse Server - 2.7.2
Database - PostgreSQL 9.5
Server OS - Ubuntu.
When I try to unsubscribe livequery, handleUnsubscribe doesn't worked, more than that handleSubscribe worked on closed activity. Help me please. My config:
class Application extends Application {
}
class BaseActivity extends AppCompatActivity {
}
The text was updated successfully, but these errors were encountered: