Closed CoolCapri closed 11 years ago
@dutchscout The problem is, when you disable internet and cancel, it works well and shows "request has been cancelled". When you have the internet and cancel, it does not cancel and still reports user with results.
I am also trying it on my Galaxy S3. The cancellation with Internet on sometimes work and sometimes doesn't. I guess that when Internet is not available or not that good, the cancellation will be successful.
@CoolCapri Hopefully this helps: https://github.com/alaurenz/metrobike/commit/c4c5f44868ae6d44f284b7f94baba612ed81f813
I added a 500ms Thread.sleep in the cancel code in Directions thread on search page. It (and a few other tweaks) seems to have helped.
Please try again!
I had tried it but it seemed not working. The sleep happens after doRequest, when doRequest has already finished with results (even if cancelled). Actually, I am not sure why backend/algorithm did not (or haven't yet) catch the interruption.
Even with the version I pushed a few minutes ago?
Yes. This is weird. Does it run well on your device?
I have tried 2000ms, it still did not work
Is it possible that dirThread.interrupt() is not properly called such that interrupt signal is not even given to dirThread?
Hmm... maybe sort of?
"The interrupt mechanism is implemented using an internal flag known as the interrupt status. Invoking Thread.interrupt sets this flag. When a thread checks for an interrupt by invoking the static method Thread.interrupted, interrupt status is cleared. The non-static isInterrupted method, which is used by one thread to query the interrupt status of another, does not change the interrupt status flag." source: http://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html So, when we check if we're interrupted, we clear the flag. I'm not sure this relates to the problem, but maybe?
It seems to run well on my device. What exactly is happening on your device? Be sure to pull / clean / rebuild / send app to device to be sure the changes are there.
This problem has been solved by Qinyuan. AlgorithmWorker has a basic misplacement of InterruptedException try-catch block.
I just pushed and the bug should be fixed. The try catch should be outside of the max query limitation if check !
Sorry, the fix did improve. But it was still not handling all the problems.
I was watching the log while running the app, and I found that, when you press cancel when algorithmWorker is preparing for its new request, the cancellation was successful. However, when the algorithmWorker is processing the request and you hit cancel at this moment, the cancellation cannot succeed (and I did see an interruption has been activiated). @alaurenz Any thoughts?
It seems now that for the most time the cancellation would be successful. I would go to re-introduced the global cancel variable as the bottom line to stop this problem. This would be that case that, although the results are found and much time passed because backend did not receive the interruption, user still gets cancellation dialog.
I just pulled the latest repo snapshot and tried it on my Nexus 7. I hit cancel button but it still shows me the results and pdCancel is still displaying. Seems like the request has not been interrupted. Did you push all your local changes to the repo?