java - Android exception handling best practice? -
if app crashes, hangs couple of seconds before i'm told android app crashed , needs close. thinking of catching exceptions in app general:
try { // ... } catch(exception e) { // ... } and make new activity explains application crashed instantly (and giving users opportunity send mail error details), instead of having delay android. there better methods of accomplishing or discouraged?
update: using nexus 5 art enabled , not noticing delay used experience apps crashing (the "hanging" talking originally). think since native code now, crash happens instantly along getting crash information. perhaps nexus 5 quick :) regardless, may not worry in future releases of android (given art going default runtime in android l).
here, check link reference.
in here create class exceptionhandler implements java.lang.thread.uncaughtexceptionhandler..
inside class life saving stuff creating stacktrace , gettin ready upload error report etc....
now comes important part i.e. how catch exception. though simple. copy following line of code in each activity after call of super method in overriden oncreate method.
thread.setdefaultuncaughtexceptionhandler(new exceptionhandler(this)); your activity may this…
public class forceclose extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); thread.setdefaultuncaughtexceptionhandler(new exceptionhandler(this)); setcontentview(r.layout.main); } } hope helps...
Comments
Post a Comment