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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:08:42+00:00 2026-06-15T23:08:42+00:00

I have a service with a BroadcastReceiver which communicates with the activity through the

  • 0

I have a service with a BroadcastReceiver which communicates with the activity through the method “exampleMethod()”. This service start and work correctly but after a while it is stopped by Android and I have to restart it. it is possible to make sure that the service is not stopped for a long time?

public class SMS_Service extends Service{
    private BroadcastReceiver rec_sms = new BroadcastReceiver() {   
        @Override
        public void onReceive(Context context, Intent intent) {
               MainActivity.exampleMethod();
        }
    };

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        return START_STICKY;
    }
  • 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-15T23:08:43+00:00Added an answer on June 15, 2026 at 11:08 pm

    after a while Service is stopped by Android

    The first thing that matters is that why your service is stopped by the android system,

    When the user is directly interacting with a component of that process (that is an activity) Android will try very hard to keep that process running, and you won’t see it killed except under extraordinary circumstances.

    • If it is due to low memory, then nothing could be done. When killing something for memory, the entire process (including the application object) is killed and no code executed in it at this point.

    • If the service is just being destroyed because it no longer needs to run, its onDestroy() will be called and when the service is later needed a new instance is created and onCreate() called.

    Is it possible to make sure that the service is not stopped for a long
    time?

    This is not possible. The closest you can get is via startForeground(), but not even that guarantees that your service will live forever.

    Moreover, this is a serious anti-pattern in Android. Users hate applications that try to run forever, which is why we have to contend with task killers and the like.

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

Sidebar

Related Questions

At boot, I have a BroadcastReceiver which launches a Service . In this Service
I have on Service that must communicate with an Activity (MyActivity) through a BradcastReceiver.
I have two classes 1.MainActivity which extends Activity and 2.AlarmReceiver which extends BroadcastReceiver. How
I have a Service and BroadcastReceiver in my application, but how do I launch
So I have a BroadcastReceiver which looks like this: public class UpdateReceiver extends BroadcastReceiver
In my app I have a service which has a BroadcastReceiver which listens to
I have strange situation in my BroadcastReceiver which uses MediaPlayer. Application crashes after certain
Is it possible that BroadcastReceiver in an activity which have gone to background receiving
My app uses a BroadcastReceiver and a service to perform background updates. I have
I currently have service classes that look something like this public class UserService :

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.