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

  • SEARCH
  • Home
  • 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 8509131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:21:06+00:00 2026-06-11T03:21:06+00:00

Lately I have been receiving informations from users about my alarm app not ringing

  • 0

Lately I have been receiving informations from users about my alarm app not ringing when it should. Finally, one of the users have send me information from build in log, that was really strange:

74. 4:25:0 - StartAlarm received
75. 5:22:15 - AlarmOnScreen create
76. 5:22:15 - Time: 04:25

Problem is, informations to log are saved as follow:

//BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent) {
    Logger.initialize(context);
    Logger.log("StartAlarm received");
    Intent i = new Intent(context, AlarmOnScreen.class);
    i.putExtras(intent.getExtras());
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}

//AlarmOnScreen (activity)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alarm_on_screen);
    Logger.log("AlarmOnScreen create");
    //Time value of alarm is logged below
    (...)

As you can see, start of the activity was delayed considerably. How is that possible? User raported that alarm was delayed until he started “using” the phone – I guess that means, until lockscreen was unlocked or screen turned on. I am still waiting for answer with more informations. On other time delay was only 5 minutes – every time, until user started “using phone”

Any ideas?

EDIT:
Let me add, that is something that have started happening lately, after application being out for months. I am still looking if I have maybe changed anything in manifest and in last update, but is it possible that it is somthing that happens only on new Android versions?

  • 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-11T03:21:08+00:00Added an answer on June 11, 2026 at 3:21 am

    I think your problem is about using AlarmManager without proper use of WakeLocks, when device “sleeps” with screen turned-off, your receiver will not work properly.

    I guess your receiver got onReceive() from AlarmManager, which is most probably was started with _WAKEUP flag like this:

    mAlarmManager.set(AlarmManager.RTC_WAKEUP, .......);
    

    This _WAKEUP flag means that device will “turn-on” even if it will be in a sleep mode.
    However, as described by documentation here ( http://developer.android.com/reference/android/app/AlarmManager.html ) :

    The Alarm Manager holds a CPU wake lock as long as the alarm receiver’s onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver called Context.startService(), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.

    In your code that means that system goes back to sleep as soon as onReceive() ends, and as startActivity(i) doesn’t work synchronously – that leads directly to the problem, mentioned above – it will be launched, but much, much later, just when user will turn the screen on.

    To solve it, I would recommend doing something like this:

    //BroadcastReceiver
    @Override
    public void onReceive(Context context, Intent intent) {
        Logger.initialize(context);
        Logger.log("StartAlarm received");
        Intent i = new Intent(context, AlarmOnScreen.class);
        i.putExtras(intent.getExtras());
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
        AlarmOnScreen.acquireLock(context);
        //Before, system could sleep right after this line(not exactly, however) and activity actually would be started much later
    }
    
    //AlarmOnScreen (activity)
    
    private static WakeLock sWakeLock;
    public static void acquireLock(Context context) {
        PowerManager pm = (PowerManager)  context.getSystemService(Context.POWER_SERVICE);
        sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "providersLock");
        //Limit 10 sec, if something wrong will happen - we'll not drain the battery to much.
        sWakeLock.acquire(10000); 
        //As we are acquiring and releasing only once - we don't need a counter.
        sWakeLock.setReferenceCounted(false);
    }
    
    private static void releaseLock(Context context) {
        try {
            sWakeLock.release();
        } catch (Exception e) {
            //In case it's already auto-released
            e.printStackTrace();
        }
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alarm_on_screen);
        Logger.log("AlarmOnScreen create");
        //Time value of alarm is logged below
        (...)
    
    @Override
    protected void onResume() {
        releaseLock(this);
    }
    

    This solution will work for the first time and will let you understand the problem deeper. To test – just start to use your alarms when screen is off and, possibly, cable is plugged-off, but I’m not sure if the last is really needed to get device into sleep mode.

    However, I would highly recommend to implement more elegant solution, suitable for your project, because current static-reference design is pretty poor, as it doesn’t work perfectly in racing conditions, for example.

    Hope it helps and please let me know if any questions.
    Good luck.

    UPD:
    I think I will also suggest to use not only PARTIAL_WAKE_LOCK, but FULL one. Like:

    pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 
        | PowerManager.ACQUIRE_CAUSES_WAKEUP, "providersLock");
    

    That will force the screen to be ON anyway, not depending on previous state and platform reaction on new activity creation.

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

Sidebar

Related Questions

I have been dealing with FTP lately and I'm not sure about the security
Lately I have been thinking about developing some basic android app. Its only due
Lately I have been reading a lot of blog topics about big sites(facebook, twitter,
I have lately been developing a very simple app for iOS with PhoneGap. All
Hey guys, lately I have been asking quite a few questions about memory management
i have been lately introduced to method chaining, and am not sure if what
Lately I have been reading about the Rack architecture in Passenger/Rails, and how it
I have been looking into different algorithms lately and have read quite alot about
I have been doing some Winsock programming lately. I do not do much stuff
Lately I have been thinking about investing in a worthy USB pen drive (something

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.