Wednesday, August 19, 2015

BroadCastReceiver and Worker thread

Don’t start a worker thread from a broadcast receiver

As soon as the onReceive () method of the broadcast receiver returns , the broadcastreciever object is marked for Garbage Collection . BroadCastReceiever Is really a transient object so don’t try to run long running task in the onReceive () itself.

Good thing would be to start a service rathan than starting a worker thread in broadcastreceiver class. 
Lets say if Broadcastreceiver was the only application component in memory then as soon as the onReceive () method returns , system thinks that its an empty process and might just kill the application in the interest of freeing up memory cause these are the ideal candidates to get killed first and system is unaware that you have started a worker thread .


Since service is an application component system will see that component running and will not touch it unless otherwise there is really no option.


System will try to keep that process around yey :-.after all isnt that what we want as an application developers

No comments:

Post a Comment