Search code examples
androidswiftfatal-error

Is there an Android equivalent to iOS´s (swifts) fatalError()?


If something happens in my app I want to kill the app there and then. In swift I can use fatalError(), is there a java equivalent?


Solution

  • I don't there's any method equivalent to fatalError in Android.

    If you want to kill the entire process then you can use android.os.Process.killProcess(android.os.Process.myPid());.

    To mimic the same behaviour of fatalError you'll probably have to implement it yourself.

    The behaviour you'll need to add besides killing the process is

    • to log a message, you can to this by using Log
    • print the file and line number, for this you can follow this thread on SO