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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:38:43+00:00 2026-06-17T15:38:43+00:00

my broadcast is getting called but PhoneStateListener is not called my code works fine

  • 0

my broadcast is getting called but PhoneStateListener is not called my code works fine when I run it in emulator but when I try it on actual device PhoneStateListener never gets a call, I am going nutts on this problem
Here is my code:

TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); //TelephonyManager object  
                            CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();  
                            telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); //Register our listener with TelephonyManager 

the above code is in onReceive() method and here is my class extensing PhoneStateListener
outside onReceive() but in broadcast class.

public class CustomPhoneStateListener extends PhoneStateListener {  

        private static final String TAG = "CustomPhoneStateListener";  



        @Override  
        public void onCallStateChanged(int state, String phonenumber){  

            if(phonenumber!=null && phonenumber.length()>0) 
                incoming_nr=phonenumber;   
            act=new Call_RecorderActivity();

            switch(state){  
                case TelephonyManager.CALL_STATE_RINGING:  
                        Log.d(TAG, "CALL_STATE_RINGING");  
                        prev_state=state;  


                        break;  


                case TelephonyManager.CALL_STATE_OFFHOOK:  
                Log.d(TAG, "CALL_STATE_OFFHOOK");  
                prev_state=state;  

                break;  


                case TelephonyManager.CALL_STATE_IDLE:  
                     prev_state=state;
                     Log.d(TAG, "CALL_STATE_IDLE==>"+incoming_nr);



                    break;  
                   // Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
                   // |Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

            } //switch close
        }
}

logcat shows this on incoming call

01-22 11:25:12.529: I/IncomingCallReceiver(1463): Bundle[mParcelledData.dataSize=168]
01-22 11:25:12.539: I/IncomingCallReceiver(1463): State: RINGING
01-22 11:25:12.539: I/IncomingCallReceiver(1463): Incomng Number: +9184848xxxx2
01-22 11:25:12.779: D/CustomPhoneStateListener(1463): CALL_STATE_IDLE==>+9184848xxxx2
01-22 11:25:16.299: I/IncomingCallReceiver(1463): Bundle[mParcelledData.dataSize=92]
01-22 11:25:16.299: I/IncomingCallReceiver(1463): State: OFFHOOK
01-22 11:25:18.849: I/IncomingCallReceiver(1463): Bundle[mParcelledData.dataSize=88]
01-22 11:25:18.849: I/IncomingCallReceiver(1463): State: IDLE

Any suggestion related to it will be accepted
Thanks in advance

  • 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-17T15:38:44+00:00Added an answer on June 17, 2026 at 3:38 pm

    Your service is getting cleaned up before the callback gets invoked. You should not really be relying on anything allocated in your BroadcastReceiver to exist after onReceive exits. You should put CustomPhoneStateListener in Service or Activity. Then you can use an Intent to launch the activity or service to do your state monitoring.

    From the BroadcastReceiver docs,

    Once you return from onReceive(), the BroadcastReceiver is no longer
    active, and its hosting process is only as important as any other
    application components that are running in it. This is especially
    important because if that process was only hosting the
    BroadcastReceiver (a common case for applications that the user has
    never or not recently interacted with), then upon returning from
    onReceive() the system will consider its process to be empty and
    aggressively kill it so that resources are available for other more
    important processes.

    The reason it is working on the emulator is probably because there are less processes in general on the emulator and for some reason it seems less aggressive about killing off processes.

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

Sidebar

Related Questions

i have defined a receiver for NEW_OUTGOING_CALL broadcast. But this is not getting invoked.
I am recording an audio file on my broadcast but I am not getting
I am trying to play RTSP live streaming url rtsp://164.100.51.207/broadcast/DDLive. But i am getting
Using Node.js and socket.io, the following works fine unti trying to broadcast back to
My broadcast receiver is Still getting execute even if My application is not working.
I am getting this broken pipe error when I try to run one of
There was an issue in getting an global data into an BroadCast receiver Class,
Basically I want to broadcast and receive every 5 seconds using this code: private
I am getting the cursor value zero when i access it from Broadcast Receiver
I get this issue in ICS, but not in previous versions: From App1, I

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.