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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:49:29+00:00 2026-05-30T19:49:29+00:00

I have created a BackgroundService class which extends Service class. I have a Timer

  • 0

I have created a BackgroundService class which extends Service class.

I have a Timer which keeps track of the duration between checks. In the onCreate method I set it for 10 seconds, so the behavior I’m expecting is that it sends a status notification message every 10 seconds. The issue I’m having is that every 10 seconds, I hear the status notification “sound” as I enabled it, but I do not see the text reminder on the top of the screen, which only appears on the first notification service alert. Does anyone know how to fix this?

I attached a good deal of source for this class below: Thanks in Advance!

private Timer timer;

private TimerTask updateTask = new TimerTask() {
    @Override
    public void run() {
        Log.i(TAG, "Timer task doing work!");   

        // Process junk here:
        sendNotification("Please leave in 5 min!!!");
    }
};

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    Log.i(TAG, "Background Service creating");

    timer = new Timer("DurationTimer");
    timer.schedule(updateTask, 1000L, 10*1000L);
}

public void sendNotification(CharSequence message)
{
    // Execute Check and Notify
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.simon;
    CharSequence tickerText = message;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    CharSequence contentTitle = "LEAVE NOW!";
    CharSequence contentText = "LEAVE NOW!!";
    Intent notificationIntent = new Intent(this, BackgroundService.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.defaults |= Notification.DEFAULT_SOUND;
    //notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    int HELLO_ID = 1;
    mNotificationManager.notify(HELLO_ID, notification);
}
  • 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-30T19:49:30+00:00Added an answer on May 30, 2026 at 7:49 pm

    Change the value of contentText with each iteration.

    Example:

    CharSequence contentText = "LEAVE NOW!! " + System.currentTimeMillis();
    

    I think you will find that the message text changes constantly because you already have a Notification with the same ID as the Notification you wish to send. So what happens is that the text is simply changed.

    Another way:

    mNotificationManager.clear(HELLO_ID);
    

    Do that before you create the new Notification.

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

Sidebar

Related Questions

I have created a windows service which is set to start automatically. This service
I have created a C# class file by using a XSD-file as an input.
I have created a simple web service called TimeServerBean . It's working properly, the
I have created an xPages application which uses a lot of server side javascript
I have created a module in Magento which takes certain views from customers about
I have created plugin for background service (to run the application in background) in
Have created a ATL COM project through which I am inserting Menu Items to
have created REST service using servicestack and in post request I have return object
I have created a PHP form, which, upon submission, goes to another PHP page.
i have created a running process which listens for input: listen = Popen([home/user/listen], stdout=PIPE,

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.