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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:01:07+00:00 2026-06-18T06:01:07+00:00

how can I get rid of the compile error? sendBroadcast(intent); this method works well

  • 0

how can I get rid of the compile error?

sendBroadcast(intent);

this method works well in another app that I made, however it has a compile error in the current app. the red underline has the eror message “undefined for the type new Runnable”

sendBroadcast() is part of the Context class, not the Intent class.

  public class Server {  // external class

  public class ServerThread implements Runnable {  // nested class

  public void run() {
        try {
            if (SERVERIP != null) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        serverStatus = "Listening on IP: " + SERVERIP;
                    }
                });
                serverSocket = new ServerSocket(SERVERPORT);
                while (true) {
                    // listen for incoming clients
                    Socket client = serverSocket.accept();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            Intent intent = new Intent();
                            intent.setAction("com.example.AudioPlay");
                            intent.putExtra("serverStatus","Connected");
                                sendBroadcast(intent);
                        }
                    });

<<<< EDIT >>>>

I changed the focus of the question to the compile error. The method works fine in the other app. It is in this particular situation where I am puzzled about the compile error.

  • 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-18T06:01:08+00:00Added an answer on June 18, 2026 at 6:01 am

    for accessing sendBroadcast method in a class which is not extending Activity, service or other Application components you will need to pass component context to it using class constructor as :

    public class ServerThread implements Runnable {  // nested class
    
    Context context;  //<< declare context here
    
    public ServerThread(Context context){
      this.context=context;
    }
      public void run() {
    
           handler.post(new Runnable() {
               @Override
                 public void run() {
                      Intent intent = new Intent();
                      intent.setAction("com.example.AudioPlay");
                      intent.putExtra("serverStatus","Connected");
                       // use context for calling sendBroadcast
                      context.sendBroadcast(intent);
                   }
        });
    

    and pass context like from Activity as :

    ServerThread serverth=new ServerThread(Your_Current_Activity.this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is this options menu button and how I can get rid of it?
I have a pretty nasty error I can't get rid of. Here's the function
I'm converting to ARC, and can't find any way to get rid of this
I can't get rid of compiler warning when I define property inside protocol. Strange
Can optimizers get rid of bad uses of spatial locality? I'm maintaining some code
How can I get rid of HTML tags in a Smarty block? I've tried
How can i get rid of trailing spaces in preg_split result without using preg_replace
Can someone figure out how to get rid of the NOT EXISTS statements in
I can't seem to get rid of these seemingly random compiles errors in one
Can get all triples with value null in specific field? All people with date_of_birth

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.