Question

I have registered my app to send a broadcast at some particular time using the alarm manager, and have set a receiver to listen to that broadcast.

Now there can be 2 cases:

  1. The OS feels there is a memory crunch and removes the app from the background. The android documentation says that the OS will ensure that my receiver receives my broadcast. Is it true ? How can I test such case ?
  2. A user decides to close my app using any task killer. Will I receive broadcast in such case too ? If not then is there any way to handle such case ?
Was it helpful?

Solution

The OS feels there is a memory crunch and removes the app from the background.

Your receiver will not be in memory anyway. Your receiver for use with AlarmManager should be registered in the manifest, and those receivers live only as long as it takes for onReceive() to run.

Is it true ?

Yes.

How can I test such case ?

Every test will test this case, if your receiver is registered in the manifest.

A user decides to close my app using any task killer. Will I receive broadcast in such case too ?

On Android 2.1 and earlier, no. Task killers there also eliminate scheduled alarms.

If not then is there any way to handle such case ?

Not really, which is why this was eliminated with Android 2.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top