java - How to send android app logs to remote server? -


in application, want send logs in case of crash remote server. have added try-catch block , in catch i'm sending logs server. want know exceptions should catch. need logs in case of every crash can fix it. practice catch exceptions?

thanks in advance.

here summarized list of suggestions curated other great answers:

  • catch unhandled exceptions.

    1. create exceptionhandler implements java.lang.thread.uncaughtexceptionhandler. can use class customize , log errors.

    2. put this: thread.setdefaultuncaughtexceptionhandler(new uncaughtexceptionhandler(this)); inside oncreate() method (after super()) of each of activity class .

    3. for details, please refer great answer android exception handling best practice .

  • enclose try/catch around codes run externally/from outside. (e.g - codes using 3rd party components)

  • enclose try/catch around codes know, can fail on conditions

    1. when there no internet connections
    2. during i/o operations
    3. when there potential crazy user inputs
    4. when there potential divide 0 situations
  • use try/catch @ top level because exceptions bubbled top level. so, in inner functions, if need be, can consider using throw exception. then, @ top level, catch specific exceptions , sort exception types in catch block correctly. (referred great answer: how using try catch exception handling best practice

  • for ui, should offer "continued usability" providing "limited functionality" version of app if error occurs (if error due to, example, no internet connectivity).

  • over-eager error reporting user not idea.

  • persistent error messages bad. inform user message , let user close/remove it.

reference 1 | reference 2 | reference 3 | further reading 1 | further reading 2 | further reading 3


for android library remotely log unhandled exceptions, can take @ this: android-remote-stacktrace .

  • download .jar file.
  • add java build path.
  • add internet permission: uses-permission android:name="android.permission.internet"

  • in oncreate method of activity or service, put 'exceptionhandler.register(this, "http://your.domain/path");'

  • on server, place this php file, can edit extend functionality.

Comments