Reputation: 735
Back story:
I have been building an app that does many calculations and builds complex graphs. Sometimes when the user clicks on the graph rapidly (my graph has on touch listeners, but not simultaneous crazy clicking that users will probably do) the application asks the user if they want to either "wait" or "close" the app because more times needs to be taken to calculate the values. When the user clicks "wait", everything is fine and the values are loaded. But if the user "closes" the app, then it uninitializes my code to use my Parse database and the app therefore has no access to any information, including the graph information which makes the app pointless.
Question:
Is there a way to check if the user selected "close" instead of "wait"? That way I can reinitalize the use of my database.
UPDATE:
I figured it out using strict mode.
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
I hope this helps people out.
Upvotes: 0
Views: 1980
Reputation: 15615
You need to perform such time-consuming computations in a separate worker thread. It is only when the main (UI) thread is blocked from input by computation for a certain length of time that the ANR message appears.
You should put up a "please wait" dialog or a progress bar on the main thread while loading is being performed on your worker thread, and have the worker thread post updates to the UI thread on what percentage of its loading is complete, which can then be reflected in the progress display on the UI thread, including, at the end, removing that display when loading is complete.
Upvotes: 0
Reputation: 16568
The close-or-wait
is a system generated dialog typically called as ANR on the Android platform. This dialog is the result of a scenario that your application is not responding for the last 5 seconds or so. In this case, I assume that you initiate a network call or a complex (time taking) calculation when the user clicks on a particular view. If that is the case, when the user clicks rigorously on it, the system initiates multiple threads, which in turn slows down the process further. I suggest you read the following section in the article.
How to keep your application Responsive
Hope this helps. PS:- This question is not directly related to Parse.
Upvotes: 1