Why dont you put your code in OnDestry.

like

OnDestroy() {

           telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_NONE);
 }

- Anurag Singh




On Wed, Apr 28, 2010 at 7:07 PM, zohar lerman <[email protected]> wrote:

> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to