tags:

views:

266

answers:

1

Hi,

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 ?

A: 

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.

CommonsWare
The issue with ACTION_PHONE_STATE_CHANGED is that , it will not have original application context . So I won't be able to interact (change/dismiss) with UI which is still visible to the user. Or do you think that, since UI is still visible original application context is still available and intent received from ACTION_PHONE_STATE_CHANGE broadcast will be able to interact with UI ?
Tushar
"So I won't be able to interact (change/dismiss) with UI which is still visible to the user." You said your application is being closed to free up memory. At that point, you do not have a UI. Android will not close up the foreground activity due to memory reasons. So, if you are not receiving PhoneStateListener updates from a foreground activity, memory consumption is not your problem. If you do not have a foreground activity, then there is no UI that is visible to the user.
CommonsWare
My activity is not foreground as it has to work during incoming/outgoing call. I use toast/notification area for UI.
Tushar
In that case, then you will "be able to interact (change/dismiss) with UI which is still visible to the user", insofar as you can raise or dismiss Notification objects from the BroadcastReceiver, or show Toasts, from a BroadcastReceiver.
CommonsWare