system.exit

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

China☆狼群 提交于 2019-12-03 07:54:31
This question already has an answer here: Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java 11 answers Can any one share to me difference between System.exit(0) and System.exit(-1) it is helpful if you explain with example. 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 they see. As an example, take this tiny Java program, which uses the number of command line arguments as the exit code: public

Android: Show toast after finishing application / activity

岁酱吖の 提交于 2019-12-01 18:34:36
问题 I want to show a simple toast, when exiting an application. The problem is, that the toast is not shown. I assume it is because the acitivity is finished or because of System.exit(0) , but I don't know how to solve it. Does anyone have a tip? Thanks!! In my activity I have the following code: Toast.makeText(this,"Exit application.",Toast.LENGTH_SHORT).show(); exitApp(); public void exitApp (){ App.getInstance().exit(); finish(); } And the mehod exit in App: public void exit() { System.exit(0)

System.exit() in android

試著忘記壹切 提交于 2019-11-29 06:39:47
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

Running code on program exit in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 22:38:49
Is it possible to write a method that System.exit will call when you terminate a program? Petar Minchev Use Runtime.getRuntime().addShutdownHook(Thread) . 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). 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 Runtime.halt(int) is called. lobster1234 You can add a VM shutdown hook . Look into shutdown hooks, see

How does Java's System.exit() work with try/catch/finally blocks? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 03:54:58
问题 This question already has answers here : Does a finally block always get executed in Java? (47 answers) Closed 3 years ago . I\'m aware of headaches that involve returning in try/catch/finally blocks - cases where the return in the finally is always the return for the method, even if a return in a try or catch block should be the one executed. However, does the same apply to System.exit()? For example, if I have a try block: try { //Code System.exit(0) } catch (Exception ex) { //Log the