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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:13:19+00:00 2026-05-28T11:13:19+00:00

I do have a problem working with my application. I am using AsyncTask class

  • 0

I do have a problem working with my application. I am using AsyncTask class to perform my background operation as working with Sockets. I believe it is good in Background.

Well, in my application, I have a UDP listener and a UDP sender that are listening from and to a server respectively any sort of data, and I have made async classes for both of them. Now I want both the AsyncTask classes to be executed from my main activity on a button click, that I am able to do, and I have a stop button to stop the execution, but once I click on the stop button, the thread still keeps running, the reason is, after calling the onCancelled() of AsyncTask, its calling postexecute() and in my postexecute(), I am making an object of my AsyncTask class and calling execute so that my listener and sender keeps running i.e. doinBackground() always keeps calling itself and listener and sender keeps working.

I know that making an object of Asynctask class in postexecute() is not a good idea because it will be in an infinite loop, but if I am able to cancel the execution on stop button where I am calling oncancelled(), it may work for me.

Please help me with this.

  • 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-28T11:13:20+00:00Added an answer on May 28, 2026 at 11:13 am

    I think that your problem is that when you cancel your asynkTask, you’re actually canceling only the outer most asynckTask which was called in the activity but as you’ve run other instances of your asyncTask recursively, then you’ve to cancel them all to get the whole thing stopped.

    why don’t you remove your code from inside doInBackground() and put it inside a method and call it from inside the doInBackground() as follows:

    protected Void doInBackground(Object... params) {
    while(!isCancelled()){
    //call the method
    }
    return yourReturnType;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a simple mobile web application using jQuery. The application is working good
Working on a console application using Delphi 7, and have run into a problem.
i have a problem. I am working on a chatting application. I want to
i have a strange problem. I have an ICEFaces(1.8.2) + Facelets application im working
I'm working on a c# service application and i have this problem where out
Hi I am working Android application development using titanium studio.I have developed small application.my
I am working on a web-based application using asp.net 4.0. I have some dlls
I'm working on an application developed using Zend Framework. I have defined relationships in
i have a problem while building and running an iphone application.Im using xml parsing
I have a map application using an in-house map engine on Android. I'm working

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.