Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9050955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:47:07+00:00 2026-06-16T12:47:07+00:00

I know that it is not recomended to use system.exit(0) in an Android application,

  • 0

I know that it is not recomended to use system.exit(0) in an Android application, but I was wondering if it would be ok to use it in onDestroy() since the application is allowed to be killed at that point?

The reason I am asking is in relation to this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:47:08+00:00Added an answer on June 16, 2026 at 12:47 pm
    • Do not rely that onDestroy will be called. There are situations where the OS will kill your application without calling your onDestroy.

    Just a word of advice, of course, as it does not directly apply to your scenario. If system.exit(0) was not called because the app is already killed, I’d say you’re OK. 😉

    • If your Activity.onDestroy is called, that means your process is in one of two states:

    — there’s no other component (Service or a ContentProvider) running in the app that the OS is aware of. This means that your process is most likely going to be killed by the OS immediately anyway, or will be the first one to be reclaimed if other parts of the system/other apps need physical memory. Thus calling exit(0) will achieve not much.

    — there’s another component running in your process that the system is aware of. Calling exit() in this case would terminate the process, killing your other component and potentially corrupting your data. The OS could care less of course, but your users might not appreciate it. 🙂

    • Killing voluntarily your process will not help other applications, if they have exhausted their internal Dalvik heap limit. No matter how much physical memory a device has, the OS has a limit on how much memory Dalvik is allowed to use in any process for heap allocations. Thus, it is possible that the system has free half of its memory and a particular application still hits OOM.

    The Dalvik heap limit is OEM configurable, though very few OEMs actually do make the effort to tune it up for their devices, and just go with the OS defaults. I don’t remember the specific defaults, but it’s safe to assume each app is allowed between 16MB on low-end Froyo/Gingerbread and 48MB on high-end ICS/JB phones. Heck, I’d be optimistic and bump the upper limit to 128MB (though I am yet to hear of a such a device) . 🙂

    • If your application has problems with its memory usage (implied by the linked question) and you are trying to solve it by forcing a “clean” slate on the next opening of the activity, this approach would work. Kind of. But it’s going to work for as long as your application is using activities only. The moment you throw in a ContentProvider or a Service, you can’t afford calling exit() anymore (as I mentioned above), and you will be forced to solve the problem properly. You might as well just bite the bullet and do it now. The simplest approach would be to ensure you are calling Bitmap.recycle() when you’re done with the particular bitmap. Of course, that works as long as you don’t have to keep more bitmaps in memory than you have memory, but that’s a totally separate beast altogether anyway. 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this is usually not the way to use AngularJS but I
I know that the following works but it is not that readable, is there
I know that NSDate does not represent a timezone, but perhaps someone can advise
I know that it's not possible to style any given PHP but I do
Since we know that constructor is not inherited in the child class as i
Now while I know that you can not perform inheritance like you would in
First of all, I know that UDP is not a reliable protocol but I
I know that comparison of types is not recommended, but I have some code
this is my first question here :) I know that I should not check
Ok, I know that question is not very informative.. Someome feel free to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.