2

I have a package added receiver in my Android application, and has been distributed for a couple months.

Recently I found that not all the PACKAGE_ADDED broadcasts can be received by my receiver.

looked up a while, someone said that if your app had been killed by users or system, then you will no longer get broadcasts.

My questions are:

  1. Is that true? confirmed, if you terminate your app from Settings->Applications --> force stop then your application wont receive any broadcast.
  2. How can I prevent this happening, or is there a work around?
楊惟鈞
  • 622
  • 6
  • 12

1 Answers1

0

1.Yes that is true.

2.Take a look at WakefulBroadcastReceiver that will wake up when it receives an Intent. Then make sure you spawn eg. an IntentService so it will process your work in the background.

Take a look at CommonsWare's WakefulIntentService for implementation example.

ejohansson
  • 2,832
  • 1
  • 23
  • 30
  • I tried WakefulBroadcastReceiver, but it dosen`t work when I terminate my application manually, I cannot receive any PACKAGE_ADDED broadcast anymore – 楊惟鈞 Feb 06 '14 at 02:40
  • and I assume you've registered your receiver in the Manifest and not in your code? If not make sure to register your receiver in the Manifest. – ejohansson Feb 06 '14 at 02:49
  • I have registered it in Manifest. still dosen`t work. – 楊惟鈞 Feb 06 '14 at 03:05
  • do you have the ``in the intent filter? http://stackoverflow.com/questions/10888768/package-added-broadcastreceiver-doesnt-work – ejohansson Feb 06 '14 at 14:03
  • 1
    also it seems like it might not work; http://stackoverflow.com/questions/1593022/cant-receive-broadcasts-for-package-intents/1596466#1596466. If this is true then I would take advantage of the alarm manager and register the receiver at certain intervals. – ejohansson Feb 06 '14 at 14:06
  • Thx for ur suggestions. I would take those in consideration. – 楊惟鈞 Feb 06 '14 at 16:21