Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close android application programmatically [duplicate]

Tags:

android

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?

like image 910
Mahmoud Emam Avatar asked Jul 08 '12 20:07

Mahmoud Emam


1 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.

like image 96
David Avatar answered Oct 31 '22 00:10

David