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
  • 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-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

Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This may seem like an odd question, but I have my own reasons for
I have the HTML given below: <ul id=thumbsPhotos> <li src=/images/1alvaston-hall-relaxing-lg.jpg onclick=updatePhoto (this.title)><img src=/images/1alvaston-hall-relaxing-sl.jpg width=56
I'm not really sure how to title this question but basically I have an
The title may seem a little weird but what I find around the internet
I know, I know, the title of my message may seem provocative, since boost::mutex
Sorry for the bad question title. Let's say that I have DateRange class that
Okay the question title may not have made sense... mostly because I don't know
Ok so my question title may have been a little confusing. Here's my example:

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.