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?
Asked
Active
Viewed 358 times
1
-
Put this line of code in your main activity when you want to kill your app- android.os.Process.killProcess(android.os.Process.myPid()); – Aishwarya Tiwari Mar 29 '17 at 10:10
-
1why swift? bad tag – Lu_ Mar 29 '17 at 10:12
2 Answers
1
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
0
Kotlin's Preconditions.kt file includes an error(message: Any) function that, in turn, throws an IllegalStateException[1].
As long as you're not swallowing the exception, it should kill the app much like fatalError().
[1] Source code
Nate Whittaker
- 1,866
- 15
- 14