Hi,

I am writing an application that listens to phone calls and perform
some tasks when phone call arrives.
The Application contains one activity which includes 2 buttons ‘Start’
and ‘Stop’ (where starts register the listener and stops unregister it
– see code below).

The problem starts when the application is closed ( onDestroy is
called ).
If the user pressed on the start button and exit from the application
the listener still working (which is the expected behavior) but from
now it is impossible to unregister the listener since launching new
instance of the application create new instance of phoneListener.

My question is:
1.       Is there better way to implement my requirement?
2.       Can I save the phoneListener object and reload It on
application creation?
3.       Any other idea?

Thanks

((Button) findViewById(R.id.Start)).setOnClickListener(new
View.OnClickListener() {
      public void onClick(View v) {
            telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
      }
});

((Button) findViewById(R.id.Stop)).setOnClickListener(new
View.OnClickListener() {
      public void onClick(View v) {
            telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_NONE);
      }
});

-- 
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

Reply via email to