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 8970273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:42:26+00:00 2026-06-15T17:42:26+00:00

I want to be able to execute some logic when my Android application is

  • 0

I want to be able to execute some logic when my Android application is launched and also when it exits. I understand that there is not really a concept of this as such in Android, as each activity has its own lifecycle.

Suppose I have activities A, B, C & D and A is the root activity.

Application launch:

  • I could put the logic in onCreate() for A, but this is also called when the orientation is changed and (possibly, if memory is low) if the user hits the Back key from activity B, C or D.

  • I could create a class that extends Application and put the logic in onCreate(). I tried this, but onCreate() was not called in the scenario where I press the Home key and then re-launch the application by clicking on the relevant icon in the main menu.

Application exit:

  • I could put logic in onStop() or onDestroy() for all activities, but again I need to be able to tell if this is not being called as a result of a transition to another activity in my application. Also, there is no guarantee that these functions will be called when there is low memory?.

  • I could override onLeaveUserHint() in all activities – are there any drawbacks to doing this?.

Edit (as requested by CommonsWare):

“Application launch” – my interpretation of an application launch is when one of the activities in my activity is being displayed after none of them when displayed (e.g. the user clicked on my application icon in the main menu).

“Application exit” – my interpretation of an application “exit” is when none of my activities are being displayed as a result of the user intentionally leaving an activity after one of them were displayed (e.g. by pressing the “Home” key or “Back” key).

(I hope this provides some clarification).

  • 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-15T17:42:27+00:00Added an answer on June 15, 2026 at 5:42 pm

    If you need to put your “Logic” in Activity and call it only once on start of app and on exit you can do something like:

    App starts, you check in shared preferences is the app started for the first time – if yes -> Do your logic and save in shared preferences that you are finished.

    You can override onBackPressed() when user finishes with the app, do whatever you like and save whatever state of the app you need so that you can again call your “logic” when app starts again.

    Is that what you had in mind ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to execute some code on every request that stuffs
I want to simply be able to click a button and execute some ExtJS
I've got maven project that I want to be able to move some properties
I have an empty select element, I want to execute some code when that
I want to be able to execute Behat based test scenarios within Jenkins. Behat
I want to be able to measure the time it take to execute an
I want to be able to take an image that i have already captured
I want to be able to replicate only the folder structure (not the contents)
I'm incorporating a GWT application in my website and I need to execute some
I am running python commands on solaris environment. I am not able to execute

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.