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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:16:16+00:00 2026-05-27T16:16:16+00:00

My situation is that I want to call a particular method to get called

  • 0

My situation is that I want to call a particular method to get called from ClassA from inside my ClassB which extends the BroadcastReceiver class. I understand how to do this from inside another class file etc and how to setup the BroadcastReceiver, or so I thought.

Below is the class file that extends the BroadcastReceiver.
public class WatchPhone extends BroadcastReceiver {

private ClassA classA;

@Override
public void onReceive(Context context, Intent BackToMain) {
    // TODO Auto-generated method stub
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
    int state = telephony.getCallState(); 
    switch(state) { 
        case TelephonyManager.CALL_STATE_RINGING:
            Log.d("TestServiceReceiver", "IDLE"); 
            classA.IwantToDoThis();
            break; 
    }
}

The method that I am trying to call does work great in the application if I manually request it.
In my AndroidManifest.xml I added this

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

and this at the bottom just above the closing application tag.

            <receiver android:name=".WatchPhone">
                    <intent-filter> 
                    <action android:name="android.intent.action.PHONE_STATE" /> 
                    </intent-filter> 
            </receiver>

When the phone rings, the application crashes then closes. Any ideas on what I should do.

  • 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-27T16:16:16+00:00Added an answer on May 27, 2026 at 4:16 pm

    I can see one problem immediately: you declared an instance of ClassA but did not instantiate it. That means classA = null and you are probably getting a NullPointerException when you use it.

    Try this instead:

    private ClassA classA = new ClassA();
    

    Alternately, you can instantiate it near the top of onReceive():

    classA = new ClassA();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the situation: I want to call a method from a C++ module,
Here's the particular situation: I'm using a bookmarklet to call a .js that sends
I want to call a partial method from outside of the declaring class. This
Is this possible? Situation is that I want to store some XML in my
I have run into a situation where I want to ensure that a compound
I am in a situation where I want to restructure my site's urls. That
Heres the situation. Component B extends component A and overrides the init method to
So my current situation is that I want to set up a folder under
I have a situation where I want to use several server side controls, which
I have a specific situation where I've got an object that I want to

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.