Reputation: 4256
Lets put the following service in as an example:
public class MyService extends Service {
final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
//Do nothing
}
};
@Override
public void onCreate() {
super.onCreate();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(mScreenStateReceiver, intentFilter);
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mScreenStateReceiver);
}
}
Note that THIS BroadcastReceiver requires being registered at RUNTIME (lets say, Service or Activity). That is the reason I am using a Service
Supposing that this Service is going to be running the whole time the device is turned on, have a working BroadcastReceiver and is doing nothing, would it drain battery life? If it would, how much? Can make it running make the Android framework drain more battery due to have a Service or Broadcast Receiver running?
I know, I am a battery life maniac
Upvotes: 1
Views: 1235