TGIO / ParseLiveQuery

Very simple and modern implementation, it lacks tests and extra functionality at this moment but i'm working on it.
Apache License 2.0
48 stars 10 forks source link

Subscription cant be cancel --crashes app #18

Closed madibalive closed 7 years ago

madibalive commented 7 years ago

Hi, really love your library ,but am currently facing an issue with the subscription connect and disconnect ,as per your example you disconnect using a button click which is located in the same block the subscription initialisation ,

However in my use case i need to unsubscribe on the OnStop lifecycle , but it seem to now work as expected , on exit and enter of activity calling the subscription call , get this error

Caused by : java.lang.IllegalStateException: closed when i called subscribe();

Subscription sub = new BaseQuery.Builder("Message")
                .where("toid",toObject.getObjectId() )
                .addField("fromName")
                .addField("message")
                .build()
                .subscribe();

looking throught the source code , it seem the livequeryClient destory isnt called and cause the closed error , am currently not very good with websocket , i would really appreciate any help at all . thank you

 private void executeQueryInternal(String query) {
        if (webSocket != null) {
            try {
                webSocket.sendMessage(RequestBody.create(WebSocket.TEXT, query));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

AND HERE 

 protected static void executeQuery(BaseQuery baseQuery) {
        getInstance().executeQueryInternal(baseQuery.toString());
    }

AND HERE

 public static void registerSubscription(Subscription subscription) {
        mSubscriptions.add(subscription);
        if (isConnected()) {
            executeQuery(subscription.getQuery());
        }
    }
madibalive commented 7 years ago

i decide to override the backbutton , and only allow toolbar.setnavclick so i can have subscription scope

emadehsan commented 7 years ago

@madibalive can you please elaborate in detail?