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

  • Home
  • SEARCH
  • 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 3944592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:55:07+00:00 2026-05-20T00:55:07+00:00

This title may seem strange, so let me try to explain what I’m trying

  • 0

This title may seem strange, so let me try to explain what I’m trying to do. I have several activity classes, each representing a different view in my application. My initial activity class gets loaded when the application launches. The user enters values and eventually a TCP socket is opened, and I then use AsyncTask to listen for and respond to messages from the server. I’d like for this AsyncTask class to essentially listen until the app is closed/error condition reached, and be able to update values in other activity classes after they are started. Does this make sense (it’s been a long, frustrating night)? I know that static activity class references are bad practice, and touching the UI thread from other activities is bad as well, but I’m having trouble finding a clean solution to this problem. Maybe using AsyncTask is not the best approach here? Should I be using a service instead or something else entirely?

Thanks in advance.

  • 1 1 Answer
  • 1 View
  • 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-20T00:55:08+00:00Added an answer on May 20, 2026 at 12:55 am

    The user enters values and eventually a TCP socket is opened, and I then use AsyncTask to listen for and respond to messages from the server.

    AsyncTask is designed for short-lived operations (e.g., flash reads, flash writes, Web service calls). Use your own background thread for indefinitely-long operations.

    I’d like for this AsyncTask class to essentially listen until the app is closed/error condition reached

    There is no such concept in Android of “app is closed”, any more than there is a concept on the Web of “app is closed”.

    and be able to update values in other activity classes after they are started.

    That sounds like a job for a service, not just some random thread or AsyncTask. For starters, once your original activity that started the background thread or AsyncTask is destroyed, you gotta gotta gotta get rid of the background thread or AsyncTask.

    Should I be using a service instead or something else entirely?

    I would strongly recommend you look into services.

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

Sidebar

Related Questions

I know the title may seem strange but this is what I want to
This may seem like an odd question, but I have my own reasons for
I know this may seem like a silly question and I have attempted to
This title of the question may seem to be previously asked and answered but
This may seem like a silly title but I'm running into a small problem
my title may not explain what I am looking for, this is my current
That title may need some work. Perhaps after reading this, you may be able
The title doesn't quite capture what I mean, and this may be a duplicate.
I'm not too great with jquery and maybe this title doesn't explain too well
The title may seem a little weird but what I find around the internet

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.