As the saying goes, if you want to have no bugs, don't write a single line of code. When an app reaches the hands of users, the fewer crashes the better. Crash handling in Android is different from that in iOS. iOS crashes usually result in a flash back, while Android will display a clumsy dialog box as shown below. It’s not surprising that when your users see a crash dialog like this, they think “this class of programmers is terrible”. In Android, our applications have the concept of foreground and background. In this article, it is defined as follows: the current application has an Activity displayed (that is, the user clearly perceives that they are in the current application), which is agreed to be the foreground, otherwise it is the background. If a crash occurs in the foreground, the user will be able to clearly perceive it, but if it happens in the background, we can do some simple operations to prevent the user from noticing the crash (i.e., no crash dialog box will pop up). The principle is actually quite simple.
Check whether it is background. Here we use the number of Activities in the process as the judgment standard
The specific implementation is as follows:
Register in Application:
All that's left is to set up a custom uncaught exception handler:
This function has been basically realized. Compared with the previous rigid dialog box, it is much more friendly to kill the process silently in the background without interfering with the user. |
<<: Big data "killing familiarity" new gameplay or Apple's deep routine
>>: iOS+PWA is here, are you here?
Since the launch of the WeChat Mini Program websi...
If it is a normal product, you get what you pay f...
gossip Becoming whiter, thinner, and more beautif...
The Galaxy S8 was seen by DJ Koh, the head of Sam...
Google spent a lot of time developing the Fuchsia...
Douban is one of the most popular social networki...
As one of the new and rapidly emerging industries...
What is March 14th? White Day? Pi Day? Not only t...
With over 100 million monthly active users and 10...
SourceDNA, an app analytics service company, rele...
A bird that lived in Fujian 150 million years ago...
At present, the training on traffic improvement i...
Of course, we will continue to support the platfo...
According to foreign media 9to5mac, for a long ti...
Only data can tell whether your promotion account...