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

  • SEARCH
  • Home
  • 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 8290751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:54:06+00:00 2026-06-08T12:54:06+00:00

In the application I’m building, I need to detect the application quitting if and

  • 0

In the application I’m building, I need to detect the application quitting if and only if the application has been quit when its in the background because the OS is reclaiming memory.

From my own experimentation, the onDestroy is called on EVERY instance. I’ve tried checking for isFinishing but I’m not 100% sure which situations this isolates it to.

@Override
public void onDestroy()
{
    super.onDestroy();
    Log.i("V LIFECYCLE", "onDestroy");
    if (!isFinishing())
    {
        // are we here because the OS shut it down because of low memory?
        ApplicationPreferences pref = new ApplicationPreferences(this);
        // set persistant flag so we know next time that the user
        // initiated the kill either by a direct kill or device restart.
        pref.setThePersistantFlag(true);
        Log.i("DEBUG", "onDestroy - ensuring that the next launch will result in a log out..");
    }
}

Can anyone shed light on my issue here? Thankyou.

  • 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-08T12:54:07+00:00Added an answer on June 8, 2026 at 12:54 pm

    Through trial and error I have worked out a solution that works perfectly for anyone thats interested. I have narrowed down the case when the application state is being resumed (onResume) in the case of the OS reclaiming memory.

    public boolean wasJustCollectedByTheOS = false; 
    
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState)
    {
        super.onSaveInstanceState(savedInstanceState);
        // this flag will only be present as long as the task isn't physically killed
        // and/or the phone is not restarted.
        savedInstanceState.putLong("semiPersistantFlag", 2L);
    }
    
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        long semiPersistantFlag = savedInstanceState.getLong("semiPersistantFlag");
        if (semiPersistantFlag == 2L)
        {
            savedInstanceState.putLong("semiPersistantFlag", 0L);
            this.wasJustCollectedByTheOS = true;   
        }
    }
    
    // this gets called immediately after onRestoreInstanceState
    @Override
    public void onResume() {
        if (this.wasJustCollectedByTheOS){
            this.wasJustCollectedByTheOS = false;
            // here is the case when the resume is after an OS memory collection    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application has to detect that the device connected to the Wi-Fi network is
Application has many extension assemblies and they contain mappings for their classes. I need
Application has 7-8 activities, so I have create an application with some background music
Application names on Google Play don't need to be unique, and it's possible to
My application has one activity which starts two services but does not bind them.
Our application allows users to upload javascript, CSS, and HTML files. We need a
My application is allowed users to upload jpeg/png files.I must to detect files with
Application has a tabhost managed through TabActivity. It has option to add tabs at
// Application Drupal 7 // Problem Background My website imports product data from a
My application has a complex schema for the domain entity. It is required use

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.