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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:26:57+00:00 2026-05-22T15:26:57+00:00

I’m asking for help so my life, and more importantly my user’s lives will

  • 0

I’m asking for help so my life, and more importantly my user’s lives will not be ruined by me not knowing how to use Services and Threads correctly.

I’m not asking for a long explanation, but more of a confirmation. It’s fine if I’m dead wrong. I’m here to learn.

If I understand correctly:
1. a service runs in the background (no UI).
2. a service theoretically will run forever until it kills itself (I’m taking a big guess here)
3. a service will continue to run even when the main Activity is not visible (how about even destroyed?)

So here’s my coding question.

I’ve got my service setup and a thread. Everything works great, but it only works once. I need it to loop and keep checking back. Once it’s done run() how do I go about telling it to run() again?

public class NotifyService extends Service{

    private long mDoTask;

    NoteThread notethread;

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onCreate() {
        mDoTask = System.currentTimeMillis();
        notethread = new NoteThread();
        notethread.start(); 
    }


    public class NoteThread extends Thread {
        NotificationManager nManager;
        Notification myNote;

        @Override
        public synchronized void start() {
            super.start();
//init some stuff
        }

        @Override
        public void run() {
                    //If it's been x time since the last task, do it again
            //For testing set to every 15 seconds...
            if(mDoTask + 15000 < System.currentTimeMillis()){

//Take care of business
        mDoTask = System.currentTimeMillis();                   
            }
        }
    }
}
  • 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-22T15:26:58+00:00Added an answer on May 22, 2026 at 3:26 pm

    From the Android docs:

    A Service is an application component
    representing either an application’s
    desire to perform a longer-running
    operation while not interacting with
    the user or to supply functionality
    for other applications to use. Each
    service class must have a
    corresponding declaration in
    its package’s AndroidManifest.xml.
    Services can be started with
    Context.startService() and
    Context.bindService().

    Note that services, like other
    application objects, run in the main
    thread of their hosting process. This
    means that, if your service is going
    to do any CPU intensive (such as MP3
    playback) or blocking (such as
    networking) operations, it should
    spawn its own thread in which to do
    that work. More information on this
    can be found in Processes and Threads.
    The IntentService class is available
    as a standard implementation of
    Service that has its own thread where
    it schedules its work to be done.

    You can find a detailed discussion
    about how to create services in the
    Services document.

    In other words, a service does NOT run in the background unless you put it in a thread. If you put a service that never ends in your application without manually threading the service, then it WILL block.

    Android provides an API to do background tasks for you without having to poke around with Java threads; it’s called AsyncTask and it’s one of the few GOOD design decisions that the Android team has ever made.

    EDIT I forgot to address your question about multithreading. You don’t want to make a thread execute its run() method more than once. Either instantiate a new thread or put a while loop around the contents of the run logic that you would like to have repeated.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.