Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

You can call os._exit() to directly exit, without throwing an exception: import os os._exit(1) This bypasses all of the python shutdown logic, such as the atexit module, and will not run through the exception handling logic that you’re trying to avoid in this situation. The argument is the exit code that will be returned by … Read more

Close application and remove from recent apps/

I based my solution on guest’s above, as well as gilsaints88’s comments below (for Android L compatibility): Add this activity to your AndroidManifest.xml file: <activity android:name=”com.example.ExitActivity” android:theme=”@android:style/Theme.NoDisplay” android:autoRemoveFromRecents=”true”/> Then create a class ExitActivity.java: public class ExitActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(android.os.Build.VERSION.SDK_INT >= 21) { finishAndRemoveTask(); } else { finish(); … Read more