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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:22:39+00:00 2026-06-11T05:22:39+00:00

Possible Duplicate: Can I startService from Application#onCreate()? Can we start a service from the

  • 0

Possible Duplicate:
Can I startService from Application#onCreate()?

Can we start a service from the application class?

I want to start a service when my application starts. So instead of starting the service from the starting activity, can I use my application class for this? Thanks.

What I tried is Inside application class :

public void onCreate() {
    super.onCreate();


    Log.i("Logger", "Service Starting");
    Intent errorLoggerService = new Intent(getApplicationContext(),
            ErrorLoggerService.class);
    getApplicationContext().startService(errorLoggerService);
}
  • 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-11T05:22:41+00:00Added an answer on June 11, 2026 at 5:22 am

    Yes, you could do this before API Label 26 but not anymore.

    If your API version is less than 26

    public class MyApplication extends Application {
        public void onCreate() {
            super.onCreate();
            startService(new Intent(this, MyService.class));
        }
    }
    

    EDIT
    Don’t call getApplicationContext(), just call startService(). Also, make sure you’ve declared the service in your manifest.

    For API label 26 and above

    EDIT 2
    From official Google Docs: https://developer.android.com/guide/components/services.html#StartingAService

    Note: If your app targets API level 26 or higher, the system imposes restrictions on using or creating background services unless the app itself is in the foreground. If an app needs to create a foreground service, the app should call startForegroundService(). That method creates a background service, but the method signals to the system that the service will promote itself to the foreground. Once the service has been created, the service must call its startForeground() method within five seconds.

    So, these days, you can’t start a background service from Application. Only GUI components are able to start background service.

    Or, you can start a foreground service from background components like Application.

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

Sidebar

Related Questions

Possible Duplicate: Can i override HOME Button on my own Home-Screen from my application?
Possible Duplicate: Can I watch an NSNotification from another class? I am currently using
Possible Duplicate: Can we post on Google plus from android application? According to this
Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: Can I embed a custom font in an iPhone application? Hi I
Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB? I want
Possible Duplicate: Can PHP read the hash portion of the URL? Hi, I want
Possible Duplicate: Can I run a .NET garbage collection from WinDbg? I'm debugging a
Possible Duplicate: Can I “multiply” a string (in C#)? I want to achieve this
Possible Duplicate: Can select * usage ever be justified? Curious to hear this from

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.