2

Sometimes my app crashes for some reason and I have no control over it. I want to let the service know when the app crashes and do some other process.

Is it possible to do that?
By the way, starting from Lollipop, getRunningTasks is deprecated.

Thanks.

Yoav Kadosh
  • 4,807
  • 4
  • 39
  • 56
Mike Yang
  • 2,581
  • 3
  • 24
  • 27
  • What kind of Service you have? – Artur Szymański Jun 24 '16 at 03:45
  • use android service [http://stackoverflow.com/questions/12172092/check-if-activity-is-running-from-service] – Mike Yang Jun 24 '16 at 03:47
  • 1
    when app crashes, that I assume means your app is killed, in that case Android system will kill all it's components like Activity, and Service. So it means Service itself is killed. This don't leave any scope to `notify` anything to it – AADProgramming Jun 25 '16 at 19:48

2 Answers2

1

You can try to catch exception in application and then start your service. Check this answer

Community
  • 1
  • 1
thealeksandr
  • 1,686
  • 12
  • 17
1

Sometimes my app crashes for some reason and I have no control over it.

You need to debug the exact reason for crash, but in General, if you have a Service running, then Android will notice that you have a service running and not kill it so readily. However, it is still possible that Android will kill your service process if it isn't "in use".

I want to let the service know when the app crashes and do some other process.

Assuming App crashes here means your app's process is killed by Android system, and in such an event, Service will stop running when system kill your application. Basically When your application is killed by the system, all components of it are killed (activities, services, etc.).

Hence, this situation don't leave any scope to notify anything to your app's service as it is already gone with app crash.

AADProgramming
  • 6,077
  • 11
  • 38
  • 58