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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:55:42+00:00 2026-05-25T21:55:42+00:00

i am working with threads in sample application.In my application i have used 3

  • 0

i am working with threads in sample application.In my application i have used 3 threads are running in infinite loop.These 3 threads are used in android service class.when i am starting these threads then the threads are running and UI is not allowing until completion of infinite loop.but how can i stop the threads and how can i handle UI?

i have written a service class as follows:

ServiceApp.java

    public class ServiceApp extends Service
    {
  @Override
  public IBinder onBind(Intent arg0) {
    return null;
  }

@Override
public void onCreate() {
    super.onCreate();

    while(true)
    {
    Thread child1=new Thread(new Runnable() {

        @Override
        public void run() {

            try {

                function1();

            } catch (InterruptedException e) {

                e.printStackTrace();
            }

        }
    });

    child1.start();

    Thread child2=new Thread(new Runnable() {

        @Override
        public void run() {

            try {


                function2();



            } 
            catch (InterruptedException e) {

                e.printStackTrace();
            }
        }
    });

    child2.start();


    Thread child3=new Thread(new Runnable() {

        @Override
        public void run() {

            try {


                function3();


            } catch (InterruptedException e) {

                e.printStackTrace();
            }       
        }
    });

    child3.start();

Toast.makeText(ServiceApp.this, "All threads started", Toast.LENGTH_SHORT).show();

}
}

public void function1() throws InterruptedException
{
    Generic generic=new Generic(); //this for connect to web services

    String add=generic.getAdd(10,20);

    Log.v("function1", "addition from service"+add); 

    Thread.sleep(1000);

}

public void function2() throws InterruptedException
{

    Generic generic=new Generic(); //this for connect to web services

    String sub=generic.getSub(34,20);

    Log.v("function2", "subtraction from service"+sub); 

    Thread.sleep(1000);
}

public void function3() throws InterruptedException
{

    Generic generic=new Generic(); //this for connect to web services

    String mul=generic.getMul(4, 6);

    Log.v("function3", "multipicationn from service"+mul); 

    Thread.sleep(1000);
}

}

how can i stop child1,child2,child3 threads from activity class?

please any body help me?

  • 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-25T21:55:42+00:00Added an answer on May 25, 2026 at 9:55 pm

    Service.onCreate() is executed inside the UI thread. You have an infinite loop there, that continuously creates more and more threads, so UI doesn’t get a chance to respond to user’s actions. If you actually intend to have so many threads, you need to create another thread that would start the original three.

    Activity can communicate with the service either via Binder (you’ll need to return an actual implementation instead of null there) or by sending intents, which you can capture and process in Service.onStart()

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

Sidebar

Related Questions

I'm working on an image processing application where I have two threads on top
I'm working on a thread library which implement user level threads (i have something
I'm working on a multi-threaded Silverlight application. The application has two threads: Main/UI and
I am new to android development. Currently i am working on an application which
I'm working on a project that needs Jasper reporting, I have used the code
I have a simple application which was working fine until I added some code
I have a C# Windows application I'm working on where I kick off different
I have a long-running console-based application Sender that sends simple text to STDOUT using
I have a long-running console-based application Sender that sends simple text to STDOUT using
I'm rather new to working with multiple threads in a database (most of my

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.