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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:40:52+00:00 2026-05-27T01:40:52+00:00

I have developed an application which starts a custom service that fires a countdowntimer.

  • 0

I have developed an application which starts a custom service that fires a countdowntimer. The service runs a notification on the start of the timer and other on the finish.
During tests I am seeing a problem about the notification and the lock screen. I describe the tests I have done:

1) If I run the application and dont let the phone going off or locked, the service plays notification sound correctly, as if the main application (activity) is in front as not. In both situations the service fires notifications perfectly.

2) If I lock the phone and the application was in front before lock, the service plays the notification sound correctly.

3) Here is my problem: if I lock the phone and the application was not in front before lock, the notification does not sound, but the service looks like is running, because when I press the “on” button in my phone, then inmediatly after screen turn on, it plays the notification (sound and icon), just in the lock screen before I can unlock the phone.

My code in the service cancel previous notification, this is the code that run notification after timer ends:

private void notificacion_fin() {
    NotificationManager notificationManager = 
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(0);
    Notification not = new Notification();
    // Ponemos la nueva notificacion de que hemos acabado
    SharedPreferences preferences = this.getSharedPreferences("com.fsp.mypref", 0);
    String not_sound = preferences.getString("notification_tone","");
    not.audioStreamType = AudioManager.STREAM_NOTIFICATION;
    not.sound = Uri.parse(not_sound);
    if (tipo_cronometro == 1) {
        not.icon = R.drawable.ic_stat_notify_time;
        not.tickerText = "Task has finished";
    } else {
        not.icon = R.drawable.ic_stat_notify_complete;
        not.tickerText = "Type 2 task has finished";
    }
    not.when = System.currentTimeMillis();
    not.defaults |= Notification.DEFAULT_VIBRATE;
    not.vibrate = new long[] {300,300,300,300,300};
    not.flags |= Notification.FLAG_AUTO_CANCEL;
    Intent notificationIntent = new Intent(this, MyActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    not.setLatestEventInfo(this, "My app", not.tickerText, contentIntent);
    notificationManager.notify(0, not); 
    notificacion = true;
}

I suspect my problem could be something relative to the context,
could be? does anybody knows what can be happening?
why in my 3th test does not run correctly?
Any help will be wellcome.
Thanks in advance.

P.S.: When I say notification sound I mean sound+icon

  • 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-27T01:40:53+00:00Added an answer on May 27, 2026 at 1:40 am

    Well, whenever you lock the screen (within a minute or two generally) the phone goes into sleep mode. You have three options that, two of which are better.

    1. Use startForeground on your service. That way, it will be in the front essentially. But it still would be affected by sleep mode.
    2. Use a WAKE_LOCK – This is my favorite option, but it requires an extra permission in the app which ignorant users don’t generally understand.
    3. Set an alarm with Alarm Manager – Since playing a notification takes about no proccessing time, this is probably the best way to do it, and then you would send a broadcast when the alarm triggers which would cause a BroadcastReceiver to make the notification sound.

    If you need a visual countdown timer, then also run the service, but don’t rely on a service to stay awake without a WAKE_LOCK. Services also can be destroyed if the user has a bad phone or tries to use an app that uses way too much RAM – My phone would probably kill it because my phone sucks.

    I like wake locks, but Alarm Manager is probably the best way to do it.

    And the Context will stay the same regardless of the phone being awake or asleep. The context is based on the running process/class/block of code it’s in. If the context were causing a problem, I would expect it to throw an exception and force close.

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

Sidebar

Related Questions

I have developed a Win32 application using C/C++, which runs on Vista and XP.
I have developed an application which is working fine. In that i have used
I've developed an application which starts several WCF Service which use the SecurityMode.Message to
I have developed the application in which i want to set the background color
I have developed a simple location aware iPhone application which is functionally working very
Hai I have developed a standalone application in which when an user logs in,
I am developing a web application which has Chart Controls. I have developed a
I am new to iPhone world. I have developed an application, which I would
I have an application which was developed under Windows, but for gcc. The code
I have developed a Java Swing application, which uses the SwingWorker class to perform

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.