exit

Android: Quit application when press back button

半世苍凉 提交于 2019-11-27 17:03:34
In my application i want exit from app when press back button, this my code: @Override public void onBackPressed() { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit") .setMessage("Are you sure you want to exit?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setNegativeButton("No", null).show(); } it's work correctly but when i exit from app it does not exit completely and show empty page with my app logo and when i again press back button exit from app

In a Bash script, how can I exit the entire script if a certain condition occurs?

廉价感情. 提交于 2019-11-27 16:33:49
I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests. Is there a way I can do this without wrapping the entire script inside of a while loop and using breaks? Something like a dun dun dun goto? Michael Foukarakis Try this statement: exit 1 Replace 1 with appropriate error codes. See also Exit Codes With Special Meanings . Shizzmo Use set -e #!/bin/bash set -e /bin/command-that-fails /bin/command-that-fails2 The script will terminate after the first line that fails

OnExit Event For a Swing Application?

我的未来我决定 提交于 2019-11-27 16:08:36
问题 I'm developing a simple application to manage the operational part of a business using Swing, but I need that when the application exits, it performs this: updateZonas(); db.close(); But how can I do this? 回答1: Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { updateZonas(); db.close(); } }); This works for any Java application(Swing/AWT/Console) 回答2: Are you using a JFrame? if so you can try this: myframe.addWindowListener(new java.awt.event.WindowAdapter() {

Exiting while loop by pressing enter without blocking. How can I improve this method?

泄露秘密 提交于 2019-11-27 15:47:42
So I've been doing a little bit of reading up on how to exit a while loop by the user pressing the enter key and I've come up with the following: import sys, select, os switch = 1 i = 1 while switch == 1: os.system('cls' if os.name == 'nt' else 'clear') print "I'm doing stuff. Press Enter to stop me!" print i while sys.stdin in select.select([sys.stdin], [], [], 0)[0]: line = raw_input() if not line: print "Finished! =]" switch = 0 else: print "Finished! =]" switch = 0 i = i+1 Is there a way to tidy this up? In particular the "if not line" and the following "else" look messy. Can they be

Why is the exit code 255 instead of -1 in Perl?

这一生的挚爱 提交于 2019-11-27 15:38:09
Why is it that when I shift the exit code, $?, in Perl by eight, I get 255 when I expect it to be -1? Jonathan Leffler The exit status returned by 'wait()' is a 16-bit value. Of those 16 bits, the high-order 8 bits come from the low-order 8 bits of the value returned by 'exit()' — or the value returned from main() . If the program dies naturally, the low-order 8 bits of the 16 are all zero. If the program dies because of signal, the low-order 8 bits encode the signal number and a bit indicating whether a core dump happened. With a signal, the exit status is treated as zero — programs like the

Ending a Program Mid-Run

試著忘記壹切 提交于 2019-11-27 15:23:28
pythoncom.PumpMessages() From what I understand this line basically tells the program to wait forever. For my purposes it seems to be working. However, I'd like to be able to end the program given the right stimulus. How would one go about ending the above line, or stopping the program from running any further. According to these docs , pythoncom.PumpMessages() : Pumps all messages for the current thread until a WM_QUIT message. So one way to stop collecting messages is by posting a WM_QUIT message to the message queue by using the ctypes library to call PostQuitMessage : ctypes.windll.user32

How do I make a C++ console program exit?

六月ゝ 毕业季﹏ 提交于 2019-11-27 14:56:59
Is there a line of code that will terminate the program? Something like python's sys.exit() ? #include <cstdlib> ... exit( exit_code ); While you can call exit() (and may need to do so if your application encounters some fatal error), the cleanest way to exit a program is to return from main() : int main() { // do whatever your program does } // function returns and exits program When you call exit() , objects with automatic storage duration (local variables) are not destroyed before the program terminates, so you don't get proper cleanup. Those objects might need to clean up any resources

Close multiple goroutine if an error occurs in one in go

北城余情 提交于 2019-11-27 14:47:07
consider this function : func doAllWork() error { var wg sync.WaitGroup wg.Add(3) for i := 0; i < 2; i++ { go func() { defer wg.Done() for j := 0; j < 10; j++ { result, err := work(j) if err != nil { // can't use `return err` here // what sould I put instead ? os.Exit(0) } } }() } wg.Wait() return nil } In each goroutine, the function work() is called 10 times. If one call to work() returns an error in any of the running goroutines, I want all the goroutines to stop immediately, and the program to exit. Is it ok to use os.Exit() here ? How should I handle this ? Edit : this question is

Are destructors run when calling exit()? [duplicate]

前提是你 提交于 2019-11-27 14:25:42
问题 Possible Duplicate: Will exit() or an exception prevent an end-of-scope destructor from being called? In C++, when the application calls exit(3) are the destructors on the stack supposed to be run to unwind the stack? 回答1: No, most destructors are not run on exit() . C++98 §18.3/8 discusses this. Essentially, when exit is called static objects are destroyed, atexit handlers are executed, open C streams are flushed and closed, and files created by tmpfile are removed. Local automatic objects