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 7616831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:59:11+00:00 2026-05-31T02:59:11+00:00

I am having trouble identifying a problem on Android TimerTask (I believe) that is

  • 0

I am having trouble identifying a problem on Android TimerTask (I believe) that is driving me crazy,

The scenario is: I use a PhoneStateListener to start a timer after i make a call, and after certain call time reproduce a sound.

Everything works perfect but as soon as I’m not on debug mode (or simply with the phone plugged to the computer), the Sound not always sound, most of these times it doesn’t sound by the way.

My biggest problem is that I cannot identify clearly the problem because this only happens when the phone is unplugged and i cannot read the logs. I could only reproduce the issue once (no sound after call) and read the logs about it, where I realized that: onCallStateChanged was being called, the Timer was Ok, but the TimerTask was never called (or scheduled).

So, after reading some questions here, I used a Handler instead of a Timer. But i have the exact same issues. In fact, with the Handler this issue is much easier to reproduce by simply plugging and unplugging the phone (Using Timer it was more difficult to reproduce the no-sound issue).

Am I doing things wrong or do I need to implement something else?

Any comment will be appreciated,
Thanks in advance

Edit

Apparently , with the Handler this happens because the phone goes to sleep as soon as the call begins. However using wake_lock doesn’t work to prevent this, is there any other alterlative to run a thread when phone is sleep?

  • 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-05-31T02:59:13+00:00Added an answer on May 31, 2026 at 2:59 am

    Well The problem with this, as I said, was that the phone stopped timer when going to sleep during the call. I ended using the AlarmManager.

    It is important to note that the AlarmReceiver must be a public class or else the receive method will never be called.

    However, I can’t still understand why Timer worked sometimes and sometimes not.

    Regards

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

Sidebar

Related Questions

I have a very subtle bug that I'm having trouble identifying. Background: We have
I'm having some trouble identifying the problem with my html code. I've created a
Got a crash report from a beta tester and I'm having trouble identifying the
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I'm having trouble identifying a plugin (or perhaps is not even a plugin), but
I'm having trouble understanding how the static analyzer in XCode is identifying possible leaks
I'm having trouble identifying how to tell which object posted a notification. I subscribe
I'm trying to write a style but am having trouble identifying a class of
Im having trouble identifying my databases as correct and valid version of my model.
Having trouble with a horizontal scroll bar that pops up. My page is set

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.