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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:25:21+00:00 2026-06-05T08:25:21+00:00

It’s my first question on SO, I hope this question won’t be bad. I

  • 0

It’s my first question on SO, I hope this question won’t be bad.

I have a service, it starts working when user launchs an app and works until user will kill it via task killer or turn off his device.

This service has a background thread which does some work with data. I need to bind activities (from activities, not by service) and sometimes (1-2 times per 30 seconds) send data to binded activities.

Structure of my service:

public class myserv extends Service {
  public static boolean started=false;
  public class workwithdata extends Thread {
    @Override
    public synchronized void start() {
      super.start();
      //.. Not important.
    }
    @Override
    public void run() {
      if (running) return;
      while (true) {
        if(condition) mythread.sleep(30000);
        else {
          Object data = recieveMyData();
          if (!data.isEmpty()) {
            //.. Some work with recieved data, not important.
            sendDataToBindedActivities(data); //This is what I need.
          }
          mythread.sleep(10000);
        }
      }
    }
  }
  @Override
  public void onCreate() {
    super.onCreate();
    this.started=true;
    mythread = new workwithdata();
    mythread.start();
  }
}

Well, I found one question but my problem has a little differences: I don’t need to send any data to the service, I need just send some data to all binded activities (which service doesn’t know at all).

Structure for which I’m looking for:

public class myact extends Activity {
  @Override
  public void onCreate(Bundle bun) {
    super.onCreate(bun);
    if(!myserv.started) {
      Intent service = new Intent(getApplicationContext(), myserv.class);
      getApplicationContext().startService(service);
    }
    bindToService(this);
  }
  @Override
  public void onRecievedData(Object data) {
    //work with recieved data from service "myserv".
  }
}

I also tried to find some solutions in android documentation but I didn’t find what I need.

So, main question is: is it possible to work with communications from service to activities?. If no: What should I use for this purpose? If yes, just, sorry, can I ask for some code or class names, because I tried to find and didn’t…

Thank you.

  • 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-05T08:25:23+00:00Added an answer on June 5, 2026 at 8:25 am

    You need to use a RemoteCallbackList

    When your clients bind to the service, you will need to register them using RemoteCallbackList.register().

    When you want to send data to the bound clients, you do something like this:

    int count = callbackList.beginBroadcast();
    for (int i = 0; i < count; i++) {
        try {
            IMyServiceCallback client = callbackList.getBroadcastItem(i);
            client.onRecievedData(theData); // Here you callback the bound client's method
                                      //  onRecievedData() and pass "theData" back
        } catch (RemoteException e) {
            // We can safely ignore this exception. The RemoteCallbackList will take care
            //  of removing the dead object for us.
        } catch (Exception e) {
            // Not much we can do here except log it
            Log.e("while calling back remote client", e);
        }
    }
    callbackList.finishBroadcast();
    

    An example can be found here It is kinda complicated, but maybe you don’t need everything this offers. In any case, have a look.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.