I have a BroadcastReceiver for one time use.
I\'m registering it in an Activity. I can\'t put the unregisterReceiver() in onPause
I know this question already has an answer But try this Code
This code is for BatteryInfo. And it did work.
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
int level = intent.getIntExtra("level", 0);
Log.i("Battery", String.valueOf(level) + "%");
arg0.unregisterReceiver(mBatInfoReceiver);
}
};
//Below code is the Code which attaches the reciever put this code in which ever place you want.
this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
Reference for Attaching StackOverFlow / Tutorial