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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:03:37+00:00 2026-06-02T21:03:37+00:00

I have a main activity that launches: 1.- A network prone thread that writes

  • 0

I have a main activity that launches:
1.- A network prone thread that writes into a socket.
2.- A network prone service that is supposed to read from a socket.
So far I’m done with 1. but I want the information read from the socket to be shown in the main activity. I know I can pass information between the activity and the service using extras but how can I tell the activity to update and get the new data?

  • 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-02T21:03:38+00:00Added an answer on June 2, 2026 at 9:03 pm

    I guess that you could use broadcasting intents combined with a BroadcastReceiver in your main activity in order to achieve background communication.

    Here’s a snippet that can achieve this.

    (CODE PUT IN THE ACTIVITY):

    class MyActivity extends Activity{
        CustomEventReceiver mReceiver=new CustomEventReceiver();
    
        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            /*YOUR ONCREATE CODE HERE*/
    
            /*Set up filters for broadcast receiver so that your reciver
            can only receive what you want it to receive*/
            IntentFilter filter = new IntentFilter();
            filter.addAction(CustomEventReceiver.ACTION_MSG_CUSTOM1);
            filter.addCategory(Intent.CATEGORY_DEFAULT);
            registerReceiver(mReceiver, filter);
    
        }
    
        @Override
        public void onDestroy(){
            super.onDestroy();
            /*YOUR DESTROY CODE HERE*/
            unregisterReceiver(mReceiver);
        }
    
        /*YOUR CURRENT ACTIVITY OTHER CODE HERE, WHATEVER IT IS*/
    
        public class CustomEventReceiver extends BroadcastReceiver{
            public static final String ACTION_MSG_CUSTOM1 = "yourproject.action.MSG_CUSTOM1";
            @Override
            public void onReceive(Context context, Intent intent){
                if(intent.getAction().equals(ACTION_MSG_CUSTOM1)){
                    /*Fetch your extras here from the intent
                    and update your activity here.
                    Everything will be done in the UI thread*/
    
                }
            }
        }
    }
    

    Then, in your service, you simply broadcast an intent (with whatever extras you need)… Say with something like this:

    Intent tmpIntent = new Intent();
    tmpIntent.setAction(CustomEventReceiver.ACTION_MSG_CUSTOM1);
    tmpIntent.setCategory(Intent.CATEGORY_DEFAULT);
    /*put your extras here, with tmpIntent.putExtra(..., ...)*/
    sendBroadcast(tmpIntent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a widget that supposed to call an Activity of the main app
I have a main activity that launches a child activity using the following code:
I have a service that work in foreground, and when the Main activity launch
I have a Service class and an main Acitivity class which is supposed to
I have a fairly simple app that launches the camera from a menu. The
I have an Activity that starts and binds to a Service . I then
I have a home page activity that I got from an example, which works
I have an app that goes between many different activities. One activity, my main
I have the main activity which launches a loading screen activity. When the loading
In my application, I have specified a second activity that can be launched from

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.