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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:42:19+00:00 2026-06-08T06:42:19+00:00

Android newbee here, I have some code that I want to run when my

  • 0

Android newbee here, I have some code that I want to run when my android app first starts up. It checks the version of the local database and downloads a new version if the current version is out of date. I have been sticking it in the oncreate of my first activity, pretty sure there has to be a better place to put this. Any recommendations of somewhere I can put it where it will get called once on startup?

  • 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-08T06:42:21+00:00Added an answer on June 8, 2026 at 6:42 am

    You can write a custom Application class (extend from android.app.Application). Override onCreate to specify what happens when the application is started:

    public class MyApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
    
            // Do something here.
        }
    }
    

    You’ll then need to register your custom class in the manifest file:

    <application ... android:name="fully.qualified.MyApplication">
    

    Edit:

    In response to David Cesarino, I disagree with the purpose of the Application class. If you rely on the Activity‘s onCreate, then what’s to stop it from becoming the same huge class of miscellaneous purposes… if you need something to happen when the application starts, you have to write that code somewhere; and the Activity would probably become more cluttered because you have to perform Activity specific logic in it as well. If you’re worried about clutter, then separate the logic into other classes and call them from the Application. Using the SharedPreferences to determine whether or not the logic should execute seems like more of a work-around to a problem that’s already been solved.

    Dianne Hackborn seems to be referring to data, not logic, in which I totally agree. Static variables are much better than Application level variables… better scoping and type safety make maintainability/readability much easier.

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

Sidebar

Related Questions

Android newbie here. I'm using this tutorial to show some rows that I fetch
first of all, i have to tell you that i have searched here and
NEWBIE ALERT! Here's the situation. I've got an Android ListActivity class (AppWindow) that contains
here is my problemI have this code to make an autoincrement variable in oracle
I'm writing an Android app for work that shows the status of our phone
Newbie question here but for some reason I cant figure this out. I have
Newbee to Android development. I am developing a application, which have three different tabs.
android newbie here. My first game involves a custom view, which is going to
Android-newbie playing around with a SimpleCursorAdapter and I've run into a few problems that
Extreme Android developer newbie here...well, new to Android development, not development in general. I

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.