system.exit

Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java

安稳与你 提交于 2019-12-27 10:41:26
问题 I'd like to know the difference between the following in Java System.exit(0); System.exit(-1); System.exit(1); When do I have to use the above code appropriately? 回答1: The parameter of exit should qualify if the execution of the program went good or bad. It's a sort of heredity from older programming languages where it's useful to know if something went wrong and what went wrong. Exit code is 0 when execution went fine; 1 , -1 , whatever != 0 when some error occurred, you can use different

Does Android care about exit status code passed to System.exit(…)?

百般思念 提交于 2019-12-22 04:06:09
问题 If I kill an Android app with System.exit(...), does it matter what status code I pass? I couldn't find any documentation on whether Android just ignores it or whether certain ones lead to any error messages for example or have any other meaning. 回答1: This is the exit code returned by the process when it finishes; Android however does not care, but know that the error code should never be higher then 255. Here is a list of standard exit codes - some process may use their own codes. 0 Clean

System.exit() in android

无人久伴 提交于 2019-12-18 04:46:20
问题 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? 回答1: 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

Running code on program exit in Java

一曲冷凌霜 提交于 2019-12-17 06:12:40
问题 Is it possible to write a method that System.exit will call when you terminate a program? 回答1: Use Runtime.getRuntime().addShutdownHook(Thread). 回答2: Shutdown hooks are the answer... here is an article on them. They do not come without issues (some of them are discussed in the article). 回答3: You can use a shutdown hook. http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread) Note that shutdown hooks will not run if the VM aborts abnormally or

Tomcat shuts down on closing jar

大憨熊 提交于 2019-12-12 06:59:47
问题 I made a java web application that calls a main method from a jar file i included as a WebAppLibraries and when this main calls system.exit to terminate it shuts down also the web app closing tomcat. How can avoid to shut down the web app closing only the execution of that main method? 回答1: By not calling System.exit(). Instead, call the appropriate API for shutting down web-apps for your container, which is container-specific. System.exit() isn't it. See the Javadoc. It's for shutting down

System.exit() results unexecutable finally block [duplicate]

三世轮回 提交于 2019-12-10 13:46:40
问题 This question already has answers here : How does Java's System.exit() work with try/catch/finally blocks? [duplicate] (6 answers) Closed 6 years ago . I am working on My application's under maintanace module try { if (isUndermaintanace) { System.exit(1); } else { prepareResources(); } } catch (Exception e) { printStack(e); } finally { cleanResources(); } When I am passing isundermaintanace true finally not executing. What am I missing? Is there any other way to do that? 回答1: Finally 's don't

Force quit of Android App using System.exit(0) doesn't work

偶尔善良 提交于 2019-12-10 10:27:24
问题 when I try to quit my Android application by overwriting the function for the back-button of Android devices and "System.exit(0)", this doesn't work. I have an activity named "LoginActivity" and an activity named "OverviewActivity". When I start an intent in OverviewActivity to switch to LoginActivity, this works. Intent changeViewIntent = new Intent(OverviewActivity.this, LoginActivity.class); startActivity(changeViewIntent); Now I am in LoginActivity and there is the overwritten method:

difference between System.exit(0) and System.exit(-1) [duplicate]

六眼飞鱼酱① 提交于 2019-12-09 06:52:38
问题 This question already has answers here : Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java (11 answers) Closed 4 years ago . Can any one share to me difference between System.exit(0) and System.exit(-1) it is helpful if you explain with example. 回答1: It's just the difference in terms of the exit code of the process. So if anything was going to take action based on the exit code (where 0 is typically success, and non-zero usually indicates an error) you can control what

Force quit of Android App using System.exit(0) doesn't work

故事扮演 提交于 2019-12-06 04:23:29
when I try to quit my Android application by overwriting the function for the back-button of Android devices and "System.exit(0)", this doesn't work. I have an activity named "LoginActivity" and an activity named "OverviewActivity". When I start an intent in OverviewActivity to switch to LoginActivity, this works. Intent changeViewIntent = new Intent(OverviewActivity.this, LoginActivity.class); startActivity(changeViewIntent); Now I am in LoginActivity and there is the overwritten method: @Override public void onBackPressed() { System.exit(0); } But when I press the back-key (e.g. in the

Does Android care about exit status code passed to System.exit(…)?

六眼飞鱼酱① 提交于 2019-12-05 02:11:37
If I kill an Android app with System.exit(...) , does it matter what status code I pass? I couldn't find any documentation on whether Android just ignores it or whether certain ones lead to any error messages for example or have any other meaning. This is the exit code returned by the process when it finishes; Android however does not care, but know that the error code should never be higher then 255. Here is a list of standard exit codes - some process may use their own codes. 0 Clean Exit 1 General Error Catchall 2 Misuse of shell builtins 126 Command invoked execution error 127 Command not