Home » Android » Close android application programmatically

Close android application programmatically

Posted by: admin June 15, 2020 Leave a comment

Questions:

How can i close my application programmatically?

I used

   finish();

Or

android.os.Process.killProcess(android.os.Process.myPid());

Or

System.exit(0);

Or

moveTaskToBack(true);

but it closed the current running activity, but i need to close the whole application??

I need to close app to retrieve some memory and then restart application again.

Or

does there is a way to clear all memory of the application?

How to&Answers:

Using these lines in your activity:-

this.finish();
Process.killProcess( Process.myPid() ); 

will kill your whole application (assuming its running in a single process) it will also free any associated memory.

WARNING: On some phones doing this may leave bluetooth sockets dangling if you are using them.