2

How can I automatically restart my service and broadcast receiver after the application gets force close due to some error. Since I'm using inbuilt applications like calender and events. Some of the mobile doesnt support and getting force closed. How to handle those things and restart those service and broadcast receiver.

Thanks

Darren
  • 68,902
  • 24
  • 138
  • 144
kannappan
  • 2,250
  • 3
  • 25
  • 35

1 Answers1

2

Register your receiver in the AndroidManifest. That way it will be called even when your app is not running: R.styleable.AndroidManifestReceiver

You could then check in the BroadcastReceiver whether the service is still running and restart it.

See for example the class SmSForwarder here. The broadcastreceiver does not need to run because it is registerend in the AndroidManifest.xml (see line 29). Android will start the Broadcastreceiver as soon as the Intent "android.provider.Telephony.SMS_RECEIVED" is sent.

Darren
  • 68,902
  • 24
  • 138
  • 144
  • can u give answer more detaily – kannappan Apr 05 '11 at 09:34
  • in case, if my receiver is registered in class file,is it possible to get receiver even after application is closed?? – Ads Jun 06 '11 at 08:29
  • I'm pretty sure that you need to define your receiver in xml. otherwise it wont be called if your application is not running. –  Jun 06 '11 at 10:42
  • I have the same problem (http://stackoverflow.com/questions/10816434/notifications-dont-come-through-when-the-app-is-closed) but can't get my head around your answer. My manifest looks the same. Would you mind giving more detail on how/why you need to check if "the service" (not sure what service) is running? – Mike T May 31 '12 at 09:50