Kishor datta gupta
Kishor datta gupta

Reputation: 1103

Android finish() method

I previously works in c# dotnet development, there is Application.exit() type method, which instantly close the app and release the memory.

I find that android "finish()" method which was supposed to do that

but it not doing that, it continue the app and not releasing the memory. How i can exit my application, so all thread and memory will be released ?

Upvotes: 2

Views: 2006

Answers (3)

ThisIsNotMe
ThisIsNotMe

Reputation: 359

Android has 2 kinds of activities, Activity and ListActivity (extends Activity).

You can extend these two for all your app's activities being used. Use your new activity base classes to keep a stack of your activities by overriding onCreate() and finish().

In this way when you want to quit, pop your activities off the stack, one by one and call finish.

I know it's laborious, but it works for me.

Upvotes: 2

Marco Grassi
Marco Grassi

Reputation: 1202

Android does not work like that, you don't need to exit your application. If the system will need more memory or resources in the future and your application is in background, it will take care of killing your application. If there is no need your process will survive in order to guarantee a faster relaunch of your application.

Upvotes: 1

Justin Breitfeller
Justin Breitfeller

Reputation: 13801

Android isn't mean to work this way. The system will reclaim your process when it finds it necessary to reacquire that memory. Rest assured, however, that when you call finish() it does completely destroy the activity currently being viewed by the user.

That all being said, if you still want to do what you shouldn't do, calling the following will stop the VM entirely.

System.exit(1)

Upvotes: 1

Related Questions