Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:59:37+00:00 2026-06-18T11:59:37+00:00

In WakefileIntentService.java from the CWAC Wakeful library the code contains: @Override public int onStartCommand(Intent

  • 0

In WakefileIntentService.java from the CWAC Wakeful library the code contains:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    PowerManager.WakeLock lock = getLock(this.getApplicationContext());
    if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
        lock.acquire();
    }
    super.onStartCommand(intent, flags, startId);
    return(START_REDELIVER_INTENT);
}

Why do the code check for START_FLAG_REDELIVERY – what prevents the following scenario?

  1. onStartCommand() is called and the lock is acquired.
  2. The system kills the service before completion.
  3. The system re-delivers the intent with START_FLAG_REDELIVERY, causing another acquire() call on the already held lock.
  4. The service completes and calls release() once.
  5. The reference counted lock is still held forever due to being acquired twice but released only once.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:59:39+00:00Added an answer on June 18, 2026 at 11:59 am

    what prevents the following scenario?

    Your scenario implies that Android would terminate the service and leave a WakeLock outstanding. I am aware of no scenario under which this will occur. Android terminates processes, not services, and it is the OS’s responsibility to release any acquired WakeLock at that point.

    It seems strange since START_FLAG_RETRY is not handled, I’ve opened the issue https://github.com/commonsguy/cwac-wakeful/issues/10 for that.

    As I noted in that issue, while START_FLAG_REDELIVERY has decent documentation, START_FLAG_RETRY does not. I have no idea when it will get used. I have no idea what the state of the WakeLock will be based upon those undocumented causes. And so forth. It is far better to risk the occasional accidental sleep than it is to accidentally keep the CPU powered on indefinitely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few questions regarding the WakefulIntentService implementation by CWAC: 1) Is it
I have a BroadcastReceiver that listen for the SMS_SENT Intent after an SMS has
I'm using cwac-locpoll and it's been doing a great job. However, some of my
I really like the section on AlarmManager in the CWAC Advanced Android book. I
In my application, I've got CommosWare's WakefulIntentservice . From the doWakefulWork method I call
im using WakefulIntentService and i want to lunch service from doWakefulWork with wake lock,
I am bit confused after going through the questions & answers in Stackoverflow about
I have a alarm receiver start a service for every 5 mins. In the
I have a application which needs to poll data at frequent intervals. I had
In my app I use alarm manager to set an alarm, which triggers a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.