Loading...

How to Close/Exit Android Application Programmatically

Sometimes you need to close/exit your application without using hardware if any exception occurs. In this tutorial, you will learn to close/...

Sometimes you need to close/exit your application without using hardware if any exception occurs. In this tutorial, you will learn to close/exit your android application programmatically.

While closing your application when any exception occurs it is better to show an error message at first and exit your application.

Following code shows you to close/exit your running android application.

Related:
Hide and Show Android ActionBar in Any Activity
How to Convert Drawable to Bitmap in Android
How to Remove/Delete Android Project from Android Studio

Android Example: Close/Exit Android Application Programmatically


Following is the content of java activity file and XML layout File.

XML Layout File


This is XML content of android layout file where I have added a button and add onClick attribute.

res/layout/close_android_app.xml

Java Activity File


src/ ExitAndroidAppProgrammatically.java


Now, run your How to Close/Exit Android Application Programmatically application and click the Click to Close/Exit App button, your application will be closed.
Tutorial 4251739305117311394
Home item