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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:42:58+00:00 2026-06-06T00:42:58+00:00

I have an Activity that should only get created once. That is, onCreate can

  • 0

I have an Activity that should only get created once. That is, onCreate can only be called once. If it’s called again, I want the Activity to do nothing.

Is it advisable to do the following?

protected void onCreate(Bundle savedInstanceState) {
    this.setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    super.onCreate(savedInstanceState);

    if(onCreateWasCalledAlreadyBoolean) {
        setResult(RESULT_OK);
        finish();
        return;
    }

    //Do other stuff here
}
  • 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-06T00:43:00+00:00Added an answer on June 6, 2026 at 12:43 am

    I assume you understand how the activity life cycle works. I mean, you are not trying to avoid something that does not apply here (thinking that onCreate may be called multiple times whenever it just onRestarts etc.).

    Technically, it’s perfectly fine.

    However, you should be worrying more about why you need to call your activity (“A“) again if it shouldn’t be created at all, if that’s what you’re thinking.

    If you’ve caught yourself checking if your activity A was already “called” (?), this could mean the previous activity (“B“) has a mistake in the logic flow of the app, and that B instead should be checking if it must in fact start that activity A. I mean, if you need to decide if you must call an activity, check before starting it.

    I don’t think that’s applicable if you’re restarting the activity (e.g.: go Home, then navigate back), but then again you should be restarting it from where you left (B for what I can tell). You won’t be navigating back to A. And you didn’t give much detail, so I’d guess this is some kind of splash screen, like evilmage93 said.

    If that’s indeed some kind of splash screen, I would advise to show it whenever the user navigates back all the way to remove your app from the task stack (contrary to his advice). In other words, whenever the user restarts the app from its “front door”.

    Although that’s ultimately a design decision, I prefer to see the splash screen whenever the app is being loaded (“entered”) in the stack for the first time, and it should work fine if you (obviously) finish A before calling B (the splash screen is supposed to finish itself when done, even in its first run). It’s a matter of consistency: the same app should behave the same way whenever the user performs the same task (start app from its “front door”).

    Still, I answered your question covering some general aspects because you asked in such way.

    // edited:

    Finally, by looking at that onCreateWasCalledAlreadyBoolean I’m afraid you may be trying to reinvent part of the activity life cycle mechanism. In this case, don’t: proceed with your regular activity logic because the user expects that behavior. Generally I wouldn’t advise people to break the normal loading of an activity just because it was killed and restarted by the system.

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

Sidebar

Related Questions

I have an activity that starts after a certain time. Once this activity starts,
I have an activity that extends ViewFactory. The activity does nothing more than act
I have a activity that I want to rotate. I use the following in
I have a welcome screen that can be started as the first activity in
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity that launches another activity with startActivityForResult method. I would like
I have an activity that runs some ASCII control over a network port to
I have an activity that lets the user load some data when they press
I have an Activity that takes a url and plays the video with a
I have an Activity that makes a remote server call and tries to populate

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.