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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:21:17+00:00 2026-05-23T12:21:17+00:00

To begin with, this is the first Android app I’m writing, and I have

  • 0

To begin with, this is the first Android app I’m writing, and I have very little prior Java experience. So nothing is too simple — I could easily be missing anything “obvious”.

Here’s the general design I’m dealing with:

  • A long-lived bidirectional network connection.
  • Requests should go out over the network when the user interacts with the UI.
  • The UI should be updated when the responses to said requests come back — asynchronously.
  • The app will contain multiple activities.

These activities will be focused on particular areas of functionality available, all relying upon the same underlying network connection. So I want to set up this connection no matter which activity my app starts in, and have it survive across switching to another activity in my app, but I want to shut it down when switching away from my app completely.

I think I want threads. I’ve got something basic working, but not well because I don’t think I have them organized properly. I also am, so far, unable to pass data between the UI and network thread, so I can’t get requests in nor actions for responses out. So I’d appreciate any advice.

  • 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-23T12:21:17+00:00Added an answer on May 23, 2026 at 12:21 pm

    I think I want threads.

    You don’t have a choice on that front. You will need a thread that listens on your socket for incoming data. Android is no different than standard Java in that respect.

    I also am, so far, unable to pass data between the UI and network thread, so I can’t get requests in nor actions for responses out.

    Well, your thread should be managed by a Service. The network connection supports multiple activities, so no one activity should own the thread.

    You will then need to decide when the network connection should exist. Since activities come and go, you will need to decide if the network connection should only exist when one of your activities is in the foreground (in which case you would likely bind to the service with bindService() from each activity), or whether there is an explicit “start” and “stop” operation that the user must do, so the connection can live after all of your activities are gone (in which case you would likely use startService() instead of bindService()).

    Once you know when and how you are starting/stopping the service, you can decide how that service will communicate its results back to the various activities. There are tons of options, some better than others depending on your use case. Registered listeners, Messenger, broadcast Intents, a ContentProvider, and so on are all candidates. Any of those can be used by a background thread and can arrange to get data to the foreground activity on the main application thread. The other activities would typically refresh their data during onResume(), since there usually is no point in proactively updating them when they are not on the screen or may have even been kicked out of RAM.

    IOW, “advice” is several chapters in a book or two. 🙂

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

Sidebar

Related Questions

Hey,firends,This is my first post. I'm just begin to using Gcc to compile java,and
I will begin this question by admitting I am very new to MVC. The
I have a LaTeX table that looks like this: \begin{table}[!ht] \centering \small \caption{ \bf{Caption}}
I have a psql script that looks like this: -- first set of statements
This is the first part of a function I have that's causing my program
First off I am a beginner in Android development; I have been doing a
My file is like this: /begin pattern/ first match /end pattern/ other text /begin
I'm making my first game using Java on Android. I need to draw a
I have a string like this: BEGIN blabla.. END; BEGIN one two END; And
I have a code that looks something like this: struct First { int f1;

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.