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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:23:31+00:00 2026-06-14T01:23:31+00:00

Please don’t think it’s a redundant question. Please read completely. I have an infinite

  • 0

Please don’t think it’s a redundant question. Please read completely.

I have an infinite loop inside the doInBackground(Void… params) of AsyncTask. And there’s a callback function within doInBackground(). So, I am not able to terminate this task using cancel(), onCancelled() and isCancelled() approach. The problem is the execution waits at the callback function forever. So, no matter where (within doInBackground) I write this isCancelled() check to break out of the infinite loop, it doesnt get executed.

Does anyone have a solution for this kind of problem? Or anyone had a requirement similar to this?

@Override
protected void onCancelled()
{
    // Socket Close
}

@Override
    protected Void doInBackground(Void... params)
    {
        try
        {
            // Socket Open

            while (true)
            {

                socket.receive();
            }
        }
        catch (Exception e)
        {

        }
        return null;
    }
  • 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-06-14T01:23:33+00:00Added an answer on June 14, 2026 at 1:23 am

    Before you start with any receiving operations, call socket.setSoTimeout(int timeout) and give it a timeout according to your needs (If you usually wait a little time for data, you can use 1000ms or less. If it might take long to receive data, use a greater value, 10000ms for example).

    Then, in your loop, after socket.receive method, check if the task was cancelled (isCancelled() == true) and if it was, break out from the loop.

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

Sidebar

Related Questions

Please don't close this question before read my actual problem. I have seen many
I have a very amateurish question, so please don't bomb me. I work in
Please don't confuse my question with determining the key press. I don't want the
I have mutipule web projects (please don't ask me why with multipule namespaces within
I have a flash element (I know, but please don't) with a settings.xml file.
I have a VB6 application (please don't laugh) which does a lot of drawing
I am new to Python so please don't flame me if the question is
Say I have a normal CSV like # helloworld.csv hello,world,,,please don't replace quoted stuff
Please don't be deterred by the just another IE problem. I have a custom
Ok I don't want this to be a hacking advice question, so please don't

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.