PhoneStateListener events stop receiving sometime

My application process incoming/outgoing calls and shows some UI. So I use PhoneStateListener to listen changes such as CALL_STATE_IDLE , CALL_STATE_RINGING ,CALL_STATE_OFFHOOK. on receiving call to my BroacastReceiver for incoming/outgoing call.

Most of the time things work properly. But sometimes my application does not receive events of PhoneStateListener and hence it is not able to change/clear UI. From user feedback this typically occurs on HTC Hero. But I have came across this issue sometime on other devices also.

My first guess is that android is killing my application in midway during call due to memory requirement. If so, is there any way to ensure that android does not my kill application under such situation .

Any thoughts ?

Asked by: Lyndon254 | Posted: 20-01-2022

Answer 1

If so, is there any way to ensure that android does not my kill application under such situation.

No, there is not.

You may wish to consider switching away from PhoneStateListener to listening for ACTION_PHONE_STATE_CHANGED broadcast Intents. That way, your code does not need to stay running.

Answered by: Cherry827 | Posted: 21-02-2022

Answer 2

I had the same issue: after a few hours it seemed that the listening was dropped. To solve this, I created a Timer that repeats every 30 minutes the call for listening: create a Timer that calls for a TimerTask class inside the service which contains the listening requests and make the Timer call for the TimerTask class every X milliseconds. That worked for me.

Answered by: Edgar633 | Posted: 21-02-2022

Similar questions

android - Notify a service from a PhoneStateListener

I have built an application that listen to call state changes, and I want to notify a service when the call_state became IDLE. All the components I have are functional, I just need to notify (not start) a service for this. What's the correct practice, maybe using AIDL? Because, in a PhoneStateListener, I can't bind to a service. Do I have to start an activity for that?

android - how to get only active calls from PhoneStateListener

I would like to get only active calls from PhoneStateListener. I have created the listener with method onCallStateChanged. Once I dial (and the call is picked up) the state is already off-hook. Well, it doesn't really surprise me, because of the text in the API: Device call stat...

android - BroadcastReceiver called but PhoneStateListener not called

While debugging the code below, BroadcastReceiverCustom is being called but PhoneStateListenerCustom is not. For now I and doing required action in BroadcastReceiverCustom only, but maynot be best place to do it. Any suggestions why PhoneStateListener not being called?? Already spent lot of time for possible reasons, no idea?? Manifest file is all correct with correct permissions. I see no runtime exceptions. ...

java - Android Service + BroadcastReceiver, PhoneStateListener

I'm in the process of developing a phone application with a very simple GUI which initiates a service to run in the background. This service will be responsible for recording data on a local database. This data will reportedly be anything with regards to user actions the Android API allows me to get. This vary from, when a user accepts/reject call, by who, whether the phone was on silent, the location of ...

android - Trouble starting a PhoneStateListener from an ON_BOOT_COMPLETED Broadcast Receiver

I am trying to restart a PhoneStateListener after the phone has been rebooted (if my isRunning SharedPref is true... i.e. the listener was running before the reboot) Here is my code... Eclipse gives me an error on the line: final TelephonyManager telephonyManager = (TelephonyManager)getSystemService(srvcName); It says that getSystemService(String) is not defined. Anyone know why? The same basic cod...

android - Broadcast receiver and phonestatelistener

I am trying to use BroadcastReceiver to receive incoming calls. I want to register call when the call is ended. Below code gives each state (idle,ringing n offhook) more than once with the same number (its not an issue of past call). Is it because phonestatelistner is called within the service. public class IncomingCallReceiver extends BroadcastReceiver { int stateString =0; int prevStat = 0; @Over...

android - PhoneStateListener changes are not handled

I need to intercept changes in the signal strength on an android device. I've seen different approaches around in StackOverflow. In my case, it's an Android Background Service that is trying to find those changes. However, I can't see what I'm doing wrong but it looks like the changes are not intercepted and I've put the phone in different metal boxes to see if it worked. By going to settings and looking at the values ther...

java - how to get context from PhoneStateListener class

i need to call method from several classes, but i don't know how to get the right context the holding class: public class SharedData { ...... ...... public static void stop_ring(Context context){ Uri lcurUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION); Ringtone ring = RingtoneManager.getRingtone(context, lcurUri); ring.sto...

android - Need to call a activity in PhoneStateListener

I need to call a activity when the phone state comes from ringing to idle. But It says The constructor Intent(MyPhoneStateListener, Class) is undefined. How can call the activity. public class MyPhoneStateListener extends PhoneStateListener { //static String org=""; public void onCallStateChanged(int state,String incomingNumber){ switch(state){ ...

android - start mediaplayer inside class extending PhoneStateListener

i need to start MP inside class extending PhoneStateListener. i have my mp3 file inside assets. any solution as getAssets() is not working inside.

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android