I\'ve register a receiver in AndroidManifest.xml like this
Receivers are meant to act on events generated by the system and sometimes the users. There are special cases where you might want to get an instance of those yourself but this is uncommon. The whole point of having receivers is to react to system events and take some action. Unless you know what you are doing, I would recommend against creating receiver instances yourself in an activity.
If you really want to, you can do it like this
private BroadcastReceiver myReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
// do stuff
}
}
Also see this thread for related info: BroadcastReceiver as inner class
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
// Your code here to do what ever you want
}
}