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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:05:50+00:00 2026-05-25T00:05:50+00:00

I’ve been trying to figure this out for a while now and can’t figure

  • 0

I’ve been trying to figure this out for a while now and can’t figure out why this is happening. This seems like it would be simple, but I can’t get this to work out.

Here’s what I’d like to happen

When I start the application,
1. If the background Service (long running singleton service) isn’t running, start it before starting the activity.
2. Start the “homepage” activity

Updated 8/20
Here’s what is happening:


1. I start the application and the service isn’t running
2. I kick off the intent (via context.startService)
   – the context.startService is called
3. The activity runs to completion
4. The onStartCommand is run

How can I get the onStartCommand to run before the activity starts running??

Any advice on this would relieve a lot of frustration. I’ve searched the forums prior to asking this but couldn’t find anything that matches my issues

Thanks a lot!

Update

Thanks for the quick responses.
I should have mentioned that I’m already running this from an extension of Application (starting the service in the onCreate method).

In my current implementation (below), here’s what happens in order as I step through the app. I thought this would cause the service to run before the activity but the activity runs and then the service runs. This is the main point of my confusion.

1. the application onCreate is called
2. the startService method is run
3. the starting activity runs
4. the service onCreate is called
– the service onStart is never called (I’ll try the onStartCommand instead as I’m not targeting older platforms – thanks for that suggestion Alexander)

    public class MyApp extends Application {

@Override
public final void onCreate()
{

        if(!MyService.isRunning()) // this is a static method with thread lock
        {
            Intent i = new Intent(context, MyService.class);
            i.setAction(MyConstants.INTENT_START_SERVICE);
            context.startService(i);
        }
    }
}
  • 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-05-25T00:05:51+00:00Added an answer on May 25, 2026 at 12:05 am

    Thanks to Alexander O for his comment that pointed me in the right direction to getting the onStart command to run. I still can’t get the onStartCommand to run before the activity though. Any suggestions?

    My issue was that I had both an onStartCommand and an onStart function in my service.
    Apparently I didn’t understand the function of onStartCommand and thought that it was just supposed to define the service type (STICKY, NOT_STICKY).
    Once I removed onStart and moved the onStart code into onStartCommand the application began working.
    For those wondering, here’s basically what I had.

    public class MyService extends Service
    {
     ...
        @Override
        public int onStartCommand(Intent intent, int flags, int startId)
        {
                // this was being executed but didn't really do anything
                return Service.START_STICKY;
        }
        ...
        @Override
        public void onStart(Intent intent, int startId)
        {
            // logic that was never executed
            // problem fixed when I removed onStart and moved the code to onStartCommand
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.