Tuesday, September 17, 2013

[android help] Broadcast Receiver class and registerReceiver method


Broadcast Receiver class and registerReceiver method



Hi i am trying to understand Broadcast Receiver , i went through many sample codes , but still have some doubts. I wanted to know when we have to extend the Broadcast Receiver class and when should we use registerReceiver() method and when should we create object for BroadcastReceiver. In some programs i came across registerReceiver methods being used but without extending the Broadcast Receiver class. I also wanted to know how the onReceive method gets called.


Which approach should be used when?


here is the registerReceiver method: registerReceiver(new BroadcastReceiver() {



@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
........
}

}

}, new IntentFilter(SENT));


Object being created for BroadcastReceiver:


private BroadcastReceiver intentReceiver = new BroadcastReceiver() {



@Override
public void onReceive(Context context, Intent intent) {
......
}

};


Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...