The Wicked Android Crashes and How to Disarm them

Osama Raddad
MindOrks
Published in
4 min readMar 11, 2019

--

Usually in android applications exceptions and crashes might happen at any time due to human error. This article discusses the after math as well as the consequences of such issues and how to bypass most of them.

Photo by Laurie-Anne Robert on Unsplash

What exactly are the users’ expectations when using smartphones and tablets apps?

To answer this, a study, carried out online by uSamp where they surveyed 502 American mobile app users aged 18 and older stated the following: “These survey findings underscore the importance for developers to closely monitor app performance, identify problems quickly and react immediately to resolve them … freezing (76%), crashing (71%) and slow responsiveness (59%) were the primary bugbears when it came to app problems, with heavy battery usage (55%) and too many ads (53%) also mentioned. Users stressed that performance mattered the most on banking apps (74%) and maps (63%), with the latter no doubt much to the chagrin of Apple, which has had some difficulty with its own maps software on iOS 6. For almost every respondent (96%) said that they would write a bad review on an under-par app, while 44% said that they would delete the app immediately. Another 38% said that they would delete the app if it froze for more than 30 seconds with 32% and 21% respectively indicating that they would moan about the app to their friends or colleagues in person or over Facebook and Twitter. A considerable 18% would delete an app immediately if it froze for just five seconds, but 27% said that they would persist with the app if they paid for it. Those experiencing bad apps urged developers to fix the problem (89%) first and foremost, followed by offering easy refunds (65%) and a customer service number (49%).”

In the growing app economy, there’s a natural Darwinian effect, and only the best apps will survive,” said Chet Kapoor, Apigee CEO.

Photo by Tim Gouw on Unsplash

But What Can We Do?

Every developer knows that bugs come around, and at some point, someone would ship a random exception to the production code and thus might risk losing the 44% of the affected users. This is where FireCrasher comes in; it utilizes a recovery sequence in order to limit and get around the crash with minimal consequences. This sequence comes at three different levels:

  • The first level is the random behavioral crash, aka occasional crash, that can be solved by just restarting the crashed activity.
  • The second level is invoked if the restarted activity kept crashing for three consecutive times. At this stage, the crashed activity is considered dead. The library then invokes the onBackPressed() if there are other activities in the back stack.
  • The third level takes effect if there are no activities in the back stack. It basically restarts the whole application starting at the default activity.

The whole process is carried out without losing any crash reports.

Photo by Zachary Nelson on Unsplash

Great! How Can We Use It?

Add this code in your root build.gradle at the end of the repositories:

jitpack repo

Step 2. Add the dependency

the dependency line

to use the library add this code to the Application class :

FireCrasher implementation

to detainment the crash level before starting the recovery you can use:

Note: You can add any user message in the onCrash function because the crash has been moved safely to another thread.

If you choose -and you should- add a message to notify the users of the unexpected behavior, this will help you in buying the users patience for the next update. However, if you only rely on handing and hiding the crash delicately, without actually fixing the underlying bug, this may in turn frustrate the user leading them to uninstall your application.

That is it, that is all you need to get the library up and running and the apps as crash proof as possible.

The full code and implementation procedure is on github:

If you have any questions, please do not hesitate to contact and follow me at linkedin as well as github.

Like the library? give me a clap on medium and a star on github. :)

And many thanks for my friend https://www.linkedin.com/in/nasip for helping me with the library and the article.

Last but not least, Comments/Suggestions are welcome as always. Keep learning and keep sharing.

--

--