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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:46:00+00:00 2026-06-05T22:46:00+00:00

In one of my Apps I do have a FileCache in a library project.

  • 0

In one of my Apps I do have a FileCache in a library project. The App itself has a Service waiting for notfications when the FileCache in the library has cached a new file.

The library is an Android library project and included in the App.

What’s the best way to send a notification from the library to the App Service?

  • Sending a Broadcast needs to know the Receiver in the Service. This is not possible from within the library project.

  • Calling a function within the Service from the library code isn’t possible neither.

Here’s a code skeleton:

// This is in the App
public class MyService extends Service implements OnBufferingUpdateListener, OnCompletionListener, OnErrorListener, OnInfoListener, OnPreparedListener {

    public class MyBroadcastReceiver extends BroadcastReceiver {

        public static final String BROADCASTRECEIVER = "xx.yyy.zzzzz.MyService.MyBroadcastReceiver";

        @Override
        public void onReceive(final Context context, final Intent intent) {
        }
    }
}

// This is in a library project that's included in the App
public class FileCache {

    private void doThread() {
        final Handler handler = new Handler() {

            @Override
            public void handleMessage(final Message message) {

                try {
                    if (processed.size() > 0) {
                        //TODO: Notification to Service
                        processed.clear();
                    }
                } catch (NullPointerException nullPointerException) {
                    //TODO:
                }

                if (queue.size() > 0) {
                    doThread();
                } else {
                    running = false;
                }
            }
        };

        new Thread() {

            @Override
            public void run() {
                for (Map.Entry<String, QueueElement> entry : queue.entrySet()) {
                    QueueElement element = entry.getValue();
                    if (element != null) {
                        File file = fetch(element.url);
                        if (file != null) {
                            ProcessedElement processedElement = new ProcessedElement();
                            processedElement.file = file; 
                            processedElement.url = element.url; 
                            processed.put(entry.getKey(), processedElement);
                        }
                    }

                    deleteFromQueue(entry.getKey());
                }

                handler.sendEmptyMessage(0);
            }
        }.start();
    }
}
  • 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-05T22:46:01+00:00Added an answer on June 5, 2026 at 10:46 pm

    Sending a Broadcast needs to know the Receiver in the Service. This is not possible from within the library project.

    Sure it is. Have the client of your library project supply to the library enough information, via parameters on some method, to either:

    • Identify the service (e.g., service Class object), in which case you use startService() to send a command to the service, or

    • Identify the BroadcastReceiver (e.g., the action string used by its IntentFilter), in which case you use sendBroadcast()

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

Sidebar

Related Questions

I have a Django project which has two apps (one created as debug test).
Possible stupid question: let's say I have two apps contained within one project. Can
I have one library for multiple apps, all of these apps will be in
It appears that we will have to build/deploy one of our new JBoss apps
I have two cocoa-touch apps in one Xcode project. Xcode gives me iPhone/iPad related
One of my apps have recently failed certification because: my app stops background music
I have two apps: the first one is a remote service. It's manifest is:
I have a service in my app, as some other apps have, too. From
I have a website that has one database I have also Desktop apps that
I have built 2 apps: one for iPhone, one for iPad. They both build

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.