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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:21:24+00:00 2026-06-15T19:21:24+00:00

I’m developing an Android app that needs to do some updating in the background

  • 0

I’m developing an Android app that needs to do some updating in the background every hour or so. I have a background service which I’ve made Sticky. And I’m using Timer.scheduleAtFixedRate to schedule the updates.

This seems to work fine. But I’ve noticed that when I close the app, the next time the scheduled update runs, it causes Application.onCreate to get called again.

This is a problem because Application.onCreate is where I’m grabbing data down from APIs ready to display to the user. I don’t want this to happen in the background.

Is this expected behaviour? If so, perhaps I need to add a check in onCreate to see if the app is in the foreground first? Or maybe I’ve got something set up wrong?

Thanks!

p.s. It’s a Galaxy Samsung running Jelly Bean 4.2.1

Background Service code:

@EService
public class BackgroundService extends Service {

    ...

    private Timer timer = new Timer();

    private void performUpdate() {

        // Do the stuff here that we need to do on a schedule...
        Log.i(LOG_CONTEXT, "Perform scheduled update");

        ...            

    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.d(LOG_CONTEXT, "Background thread started");

        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                performUpdate();
            }
        }, 0, UPDATE_INTERVAL);

        // Sticky means service will continue running until explicitly stopped
        return START_STICKY;
    }

    @Override
    public void onDestroy() {

        Log.d(LOG_CONTEXT, "Background thread stopped");            
        timer.cancel();

    }

}

Application code:

@EApplication
public class MyApplication extends Application {

    ...

    @Override
    public void onCreate() {
        super.onCreate();
        initApp();
    }

    private void initApp() {

        // This is where I want to do stuff when the app is actually
        // opened by the user, not every time the background service
        // update occurs!

        Log.i(LOG_CONTEXT, "Initialise. Why does this happen again after app's closed?");

        ...

    }

    ...

Log:

12-09 16:28:15.828: I/MyApplication(3049): Initialise. Why does this happen again after app's closed?

[Now I close the app, by pressing the Recent Apps menu button and swiping it away]

12-09 16:28:16.015: I/BackgroundService(3049): Perform scheduled update
12-09 16:28:33.875: I/MyApplication(3080): Initialise. Why does this happen again after app's closed?
  • 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-15T19:21:25+00:00Added an answer on June 15, 2026 at 7:21 pm

    Your service runs as a part of your application, so the application is created for it.

    Most apps do not need to extend Application. Without seeing all of your code, I’m pretty sure you don’t need to either. Just extend Activity for the class that displays stuff to the user and do the API stuff in that. That will not be created when the service runs.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.