What will happen if broad cast receiver binds to binder service? Is there any problem?
No, One should not bind a service from Broadcast receiver.
Option 1 is right because, broadcast receivers will have a time limit of 10 seconds. establishing connection to a service may take more time.
No problem will occur if one binds a service from broad cast receiver.
Option 3 is right because, receivers doesn't have any time limit to finish its functionality.
One should not bind a service from Broadcast receiver. The reason is broadcast receivers are light weight components, where it has to finish its functionality with in not more than 10 seconds maximum. Else android may forcefully kill your receiver. Binding (establishing connection to) a service may take more than 10 seconds in some worst cases, that's why android won't allow it.
Rules for Broadcast Receivers:
1.Broadcast receivers will not have any UI(mostly) and it will have only background logic.
2.Broadcast receivers will have the maximum time limit of 10 sec to finish its functionality otherwise it will crash.
3.You should not do long running operations or asynchronous operations in the receiver.
Example: a. Preparing SD card. b. Uploading / Downloading files from internet. c. Creating Db files. d. Binding to services
4.Do not show dialog to the user in broadcast receiver. (this is asynchronous operation)
5.You can use “ toast” or “Notifications”.
6.Don’t write any heavy functionalities.
Back To Top