I need to create a custom broadcast receiver in an onCreate event of activity, and obviously I need to disable a broadcast receiver in an onDestroy event of activity
For clarity, this is a piece of code that I use
public class AnActivity extends Activity { private ResponseReceiver receiver; public class ResponseReceiver extends BroadcastReceiver { public static final String ACTION_RESP = "mypackagename.intent.action.MESSAGE_PROCESSED"; @Override public void onReceive(Context context, Intent intent) {
I read that onPause / onResume and onStart / onStop events for activity should also register and unregister the broadcast receiver.
I really want to understand what is considered best practice for this and why.
android broadcastreceiver
jamesc Oct 25 '11 at 9:21 2011-10-25 09:21
source share