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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:01:12+00:00 2026-05-29T06:01:12+00:00

Alright, i have read many different views on how to do this with no

  • 0

Alright, i have read many different views on how to do this with no success. Maybe i am missing something or not doing something right, so any help i appreciate…

So, i have 2 Classes. Lets say Class A is an activity and has a public method called classAmethod();

Now, Class B actually extends a BroadcastReceiver. So in Class B i need to start classAmethod();

—

So far when i try this, it will want to make it static. But i cant do that. I have tried some other methods that dont make it static but for some reason it automatically wants it to be static and if something isn’t it will FC once the method is called.

  • 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-29T06:01:13+00:00Added an answer on May 29, 2026 at 6:01 am

    There are a number of ways you can do this so I’ll just outline 2 ways I would do this.

    Option 1. use a listener

    create an interface

    public interface Listener {
    
    public abstract void onEvent();
    
    }
    

    in the broadcast receiver create a static reference and setter

    private static MessageListener mListener = null;
    
    @Override
    public void onReceive(Context context, Intent intent) {
        //stuff
            if(mListener != null)
                 mListener.onEvent();   
    }
    
    public static void setListener(Listener l) {
        mListener = l;
    }
    

    then implement the listener in the Activity

    class MyActivity implements Listener{
    
        @Override
        public void onResume(){
            //register the listener, should probably unregister in onDestroy
            BroadCastReceiver.setListener(this);
        }
    
        @Override
        public void onEvent(){
            //do something
        }
    }
    

    Option 2. use an intent

    In the broadcast receiver

    Intent intent = new Intent();
    Bundle bundleToSend = new Bundle(); 
    //BUNDLE_EXTRA,DO_SOME_ACTION and ACTION_KEY are just constants so just define them somewhere
    bundleToSend.putInt(ACTION_KEY, DO_SOME_ACTION);        
    intent.putExtra(BUNDLE_EXTRA, bundleToSend);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);
    

    The flag FLAG_ACTIVITY_SINGLE_TOP will start the activity if its not started or if it is running it will be caught in onNewIntent() so you will need to put some code in both the onCreate() and onNewIntent() to extract the bundle and check for the action.

    final Bundle bundleReceived = intent.getBundleExtra(BUNDLE_EXTRA);
    if (bundleReceived.getInt(ACTION_KEY) == DO_SOME_ACTION) {
        //do something
    }
    

    Option 1 is really only useful for when the broadcast receiver is only going to be receiving when the activity is at the forefront. Option 2 is more versatile and can be used even when the app is not running (eg the broadcast receiver is run in a service started on boot) so that the activity will be started and the action performed no matter the state of the activity.

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

Sidebar

Related Questions

Alright...I've given the site a fair search and have read over many posts about
Alright I have an xml document that looks something like this: <xml> <list> <partner>
Is it alright to have a function that is not a part of any
Alright I have been trying to figure this out and I read the MSDN
Alright so I have this C++ image capturing class. I was wondering if I
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, so I have this bit of code, and when I make the request,
Alright so this is an odd one... I have an application built in ColdFusion

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.