R
R
R6MF49T22014-05-22 12:45:24
Android
R6MF49T2, 2014-05-22 12:45:24

Android - Why doesn't the broadcast receiver fire when the device goes to sleep?

So, I am writing an application that should do some actions when the tablet is connected to the docking station.
Declared in the manifest

<receiver android:name="MyBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.DOCK_EVENT"/>
            </intent-filter>
        </receiver>
        <service android:name="PowerService"></service>

respectively, the receiver starts the service
public class MyBroadcastReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    context.startService(new Intent(context, PowerService.class));
  }

}

I display a message in the service
public int onStartCommand(Intent intent, int flags, int startId) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
    dockIntent = registerReceiver(null, ifilter);
    Toast.makeText(this, "Старт сервиса...", Toast.LENGTH_LONG).show();
    if(dockIntent != null){
//бла-бла-бла

When the tablet is connected to usb, everything works well, there are no problems. When the tablet is disconnected from yusb, everything also works until the screen is off. After the tablet goes out and I try to connect the docking station, the screen lights up but the service does not start. What could be the reason?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question