0

I know that service crash behaviour is common in android and if crash happens then service will automatically restart.

I have three services(A, B, C) which runs on bootup and one service(A) starts up other two services( B and C). So My question is if one service crashes then will there be an impact in other two services crashing at same time?

When I test these services, 80% of time if my service A crashes then other two services were also crashing and 20% of time, only one service(A/B/C) was crashing at a time.

What is the correct behaviour of this services when they crash?

Kara
  • 5,650
  • 15
  • 48
  • 55
user2291470
  • 3
  • 1
  • 2
  • When you say 'crash' do you mean that as in there are errors, or do you mean simply that the service stops? If crashing with errors, please post your logcat output. – Tom Apr 19 '13 at 14:42
  • usually after long time of running, if the memory is low then the android sevices crashes and they will be autmatically restarted... My services are not crashing with errors... they crash if the device memory is low so to reclaim the memory – user2291470 Apr 19 '13 at 14:57
  • According to the documentation, services often perform a task and when that task is completed, they stop themselves. Maybe you should look at what your services are trying to accomplish and if they are stopping themselves because they have finished their job. Also look at why memory is getting low. Also, note that even if service A gets destroyed, services B and C can keep on going. – Tom Apr 19 '13 at 15:09
  • I am not stopping my services any where... I want them to run all time. – user2291470 Apr 19 '13 at 17:16
  • http://stackoverflow.com/questions/3856767/android-keeping-a-background-service-alive-preventing-process-death – Guilherme Torres Castro Mar 12 '14 at 14:20
  • If you experience crashes, post crash logs. – OrhanC1 Mar 17 '14 at 15:30

3 Answers3

1

When the Android OS is running low on Memory it starts by closing anything that is in the background taking memory - this is the defined behavior.

You should start your Services with "START_STICKY" this way the OS will restart your services when it has memory again (this might not happen) like this:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LocalService", "Received start id " + startId + ": " + intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

See this Detailed Answer: How to force a service restart?

And you can read more about Services here: http://developer.android.com/reference/android/app/Service.html

Community
  • 1
  • 1
Raanan
  • 4,664
  • 25
  • 45
0

"My question is if one service crashes then will there be an impact in other two services crashing at same time?"

No, it won't.

"I have three services(A, B, C) which runs on bootup and one service(A) starts up other two services( B and C)."

There is nothing wrong with that, but i would suggest to start every service on bootup independly. Why? Because it would diminish otherwise unecessary aggregation between your services.

"What is the correct behaviour of this services when they crash?"

System will kill services to claim memory at its own will.

There is no "correct" or fixed order that your services can be killed, it all depends on who got more memory to release and is doing the less important stuff.

reis_eliel
  • 338
  • 2
  • 7
0

If Service A is dependent on Service B/c. than only it will cause to destroy else not.

for example, if your app using FirebaseAuth service. While gms update, FirebaseAuth services will be killed & start again, your app services will also killed & will start again.

Madhukar
  • 13
  • 3