2

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 ?

Kishor datta gupta
  • 1,103
  • 2
  • 14
  • 42
  • 2
    possible duplicate of [How to quit android application programmatically](http://stackoverflow.com/questions/6330200/how-to-quit-android-application-programmatically) – Graham Borland Mar 02 '12 at 14:56
  • 2
    Trying to quit the application in this manner is a bad idea. See this for an explanation: http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon – Graham Borland Mar 02 '12 at 14:57
  • Thanks Graham Borland, thats clear my concept – Kishor datta gupta Mar 02 '12 at 15:22

3 Answers3

2

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.

ThisIsNotMe
  • 349
  • 2
  • 10
1

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)
Justin Breitfeller
  • 13,737
  • 4
  • 39
  • 47
  • 1
    Writing System.exit(1) exits the VM in an unfriendly way. I really don't recommend using it. Perhaps it would be better if you asked a question describing what you are trying to achieve, what you expect to happen, and what is actually happening? – Justin Breitfeller Mar 02 '12 at 15:54
1

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.

Marco Grassi
  • 1,202
  • 9
  • 14
  • i always found that application is running. i write finish in exit button, but when i relunch it getting last lunch values in field. How android store these? – Kishor datta gupta Mar 02 '12 at 15:17