Pergunta

I am using Alarm Manager to get triggers every 5 minutes. The alarm receiver extends WakefulBroadcastReceiver and on receiving an alarm trigger it starts an IntentService via startWakefulService(context,service). On receiving the intent in onHandleIntent(Intent intent) method inside the service, the app performs some desired stuff and at the end of this method it releases the wake lock by calling AlarmReceiver.completeWakefulIntent(intent).

My app is running fine but in the logcat I see the warning messages by the WakefulBroadcastReceiver.

Tag: WakefulBroadcastReceiver Warning message: No active wake lock id #1

These warning messages keeps on coming with every trigger and the #number increases every time. I am wondering if there is some issue with the alarm that is set up by the application because the messages are increasing gradually in number. Or is it just because the wale-lock is not created by the alarm manager and my app is trying to remove it via completeWakefulIntent.

Foi útil?

Solução

Most likely startWakefulService and onHandleIntent were executed in different processes. In such case calling the static AlarmReceiver.completeWakefulIntent will behave as if it worked, but since the actual wake lock is not found in that process space you would get that warning message.

Outras dicas

Make sure that you have correctly typed the WAKE_LOCK permission into your android manifest. If you forgot or mis-typed it, then startWakefulService will start the service, but silently fail afterwards. You won't see anything obvious in the log cat that highlights the problem.

In my case, Android Studio had auto-completed 'WAKE_LOCK' as a lower case 'wake_lock'. The service did start, but startWakefulService never returned cleanly, which I verified with logging. Some kind of exception was getting raise.

public class FooBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Fpp receiver fired. Starting bar service");

        Intent serviceIntent = new Intent(context, BarService.class);
        startWakefulService(context, serviceIntent);
        Log.d(TAG, "Started bar service"); // << never reached!
    }

The primary indication that I had a problem was "No active wake lock id" messages showing up in the log whenever BarService called completeWakefulIntent.

Lastly, my troubles all occurred with code executing in the same physical process, so the first answer did not apply.

Note: My experience was on a Samsung Galaxy Note 10 running Kitkat 4.4.2.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top