I know system.exit(0) should not be used. I have read plenty of tutorials as well stating why it's not recommended for exiting applications and finish() is a better alternative ,but in very rare case when this dirty workaround is used than my main question is can it harm the android device or any aspect of device if used?
short answer: No.
long answer: No, it doesn't harm the device or any aspect of the device. It just removes the app from memory and cleans up all used resources. If you have any files open, they can become corrupted, but the filesystem won't. Android should release all and any resources (GPS, WiFi, etc) that you have in use at the time, but they could be in an undefined state. Compare the effects of System.exit()
to a an app-crash: that wouldn't affect your device either.
Calling System.exit(0)
anywhere outside the "main" method of an application is not recommended for the following reasons.
It is an impediment to reusing your code.
It makes unit testing hard. For example, if your code calls System.exit when some tests exercise some error handling, it will end the test on encountering System.exit(0)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With