forceclose - Keep log in text file on device when app force close on android -
my android app force close time when running on device.i want store error log in text file on device.so can see reason behind force close.because difficult identify when sudden force close occure when app running. can provide me way create log file on sd card.
thanks in advance.
i have following code when app start after adding code app not force close,and log file showing null.
thread.setdefaultuncaughtexceptionhandler(new thread.uncaughtexceptionhandler() { @override public void uncaughtexception(thread thread, throwable ex) { log.e("uncaught exception", thread.tostring()); log.e("uncaught exception", ""+ex.getmessage()); try { printwriter out = new printwriter("mnt/sdcard/log.txt"); out.println(ex.getmessage()); out.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } } });
the force close screen android default display indicates error or exception occured in code wasn't handled: can't override it, , way prevent figure out , handle exception occured in code.
there way set global exception handler, catch exception caused on thread. set in main activity , apply every subactivity.
final uncaughtexceptionhandler defaulthandler = thread.getdefaultuncaughtexceptionhandler(); thread.setdefaultuncaughtexceptionhandler(new uncaughtexceptionhandler() { public void uncaughtexception(thread thread, throwable ex) { // crash info //log file defaulthandler.uncaughtexception(thread, ex); } });
edit:
came across this:
you might try acra (application crash report android) library:
acra library enabling android application automatically post crash reports googledoc form. targetted android applications developers them data applications when crash or behave erroneously.
it's easy install in app, highly configurable , don't require host server script anywhere... reports sent google doc spreadsheet !
also link
put thread.setdefaultuncaughtexceptionhandler(new your.package.uncaughtexceptionhandler());
after super.oncreate
Comments
Post a Comment