Tushar
Tushar

Reputation: 1607

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 ?

Upvotes: 1

Views: 1532

Answers (2)

Deegital
Deegital

Reputation: 21

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.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006869

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.

Upvotes: 1

Related Questions