I shared this algorithm on the Android Developers Group when I was writing it. It wasn't finished at the time. I had worked through the logic by writing the code one step at a time, checking the results at each step, and then figuring out if those results were within the realm of possibility. Since then I have received numerous emails from other developers asking for my final solution. It turns out that my first solution was almost my final solution. The only thing I have done to the alrorithm since was to shorten it, and get rid of some redundancy. It really didn't make much difference to my program as it is only used when a user makes a new search, and therefore is only called an average of 2 or 3 times a day.
Anyway.... I'll show my original code first, because it walks through the logic. The second implementation is a little faster, but not as easy to follow the logic.
Below is what I am actually using in production. It's really not much faster, but it does allocate less variables.
If you come up with a more efficient formula, please let me know. I'm sure there are other ways to do this, but this has worked very well for me.
Good luck with it.
The Android Exception Logger is a free tool for Android developers to log exceptions in their apps, and get a detailed list of the unhandled exceptions their app is generating.
Here a list of the current and planned features for it:
- Log all unhandled exceptions.
- Exception entries can include the name of the last function called in your code, a stacktrace, the user SDK version, your software version, and the Android Id.
- The Test Developer key is limited to a few hundred log entries a day.
- The Prod Developer key is unlimited
- The basic report will show all fields logged and allow you to view the last 100 entries in chronological descending order
- (Planned) Allow sorting and grouping of the errors by exception type, SDK version etc.
- (Planned) For non-internet enabled apps build a system to allow logging via email (will require the user to approve).
- (Planned) Allow developers to get an email listing their latest exceptions
- (Planned) Figure out how to pay for this ;)
- (Planned) Figure out even better methods to get approval from the user for the developer to contact them
The BETA version of the Exception Logger is available by clicking on the "Developer/Exception Logger Manager" Link in the main menu (to the left).