0

I am working on three different services and on device bootup, one service starts other two services. Right now its working fine but some times my service crashes and it restarts itself. I know that this behaviour is common with services, if the memory is low then for reclaiming the memory service restarts itself.

I need to track the service info like getting the service crash time. Right now I retrieve the service start time by writing code in onstartCommand() and stop time in onDestroy().

What I observe is stop time in onDestroy() code does not execute when service is crashed. So Is there a way to get the service crash time?

Kara
  • 6,115
  • 16
  • 50
  • 57
user2291470
  • 3
  • 1
  • 2

1 Answers1

0

A few thoughts:

  • If it's crashing, it will leave a trace in the log file, there are some comments on reading it here: Android read error log from handset

  • If it's being closed by the system in a normal way, it should go through onDestroy.

  • If it's going through the slightly mysterious "close, restart" effect that has been reported elsewhere, then it doesn't seem to hit the log, but the two events seem to be very close in time, and this effect seems to be stopped by making the services run in separate processed. (Android service onCreate is called multiple times without calling onDestroy and possibly Service being re-Created by AlarmManager).

  • From a state management perspective, if you store the time the service last did something of note (ie keep a stored time of when it does something of note and update it everytime it does something of note) then you will have a good estimate.

Community
  • 1
  • 1
Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
  • I can actually read the next onStartCommand(), but this wont solve my issue. There should be a difference between service crash time and stopService() time. I wanted to know when at what times service crashes. – user2291470 Apr 17 '13 at 17:17
  • I've tried to update the answer to clarify the three scenarios I'm aware of, or is this a different one? – Neil Townsend Apr 17 '13 at 17:30