> TelephonyManager tm = (TelephonyManager)getSystemService > (TELEPHONY_SERVICE); > tm.listen(mPhoneListener, PhoneStateListener.LISTEN_NONE); > > This seems to work for a while but then fails to fire after - say an > hour.
This sounds very much like a problem I have and wrote about at http://www.anddev.org/crash_recovery_makes_my_widget_useless-t9163.html > I have tried relaunching the listening in a timertask every 60 seconds > but this does not seem to work. Yep :-), I have also tried to use a timertask and that get lost as well as the PhoneStateListener together with some other global variables. > Is there a way of keeping a listener alive for a long period of time. I wish I knew. The timertask idea might work if the timertask is replaced with an AlarmManager. However, I still don't like the idea to do periodic checks to see if something has become broken. Those periodic checks will consume battery if done often but if done seldom there is instead a bigger risk of not having a working PhoneStateListener when the phone state changes. > I can only assume the system is garbage collecting it. According to my studies of the logs it seems as if the PhoneStateListener disappears because the application crashes and then is recovered in a less useful state. regards Henrik -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en