Incorporating actions to switch activities On and Off
<p>I have a tutorial app that is working (great!) but I want to add some extra finesse to it. Effectively the app will broadcast the current location of the receiving smartphone which someone may not want to happen all the time. My sample code below shows 3 hard coded scenarios:</p>

<ul>
<li>The first chunk of code has been commented out but shows the real code used to broadcast a users location.</li>
<li>The second chunk is active and is currently broadcasting an "I'm not telling you" message.</li>
<li>The third is some sample code which has been commented out code which makes people think I'm at Google HQ.</li>
</ul>

<p>So (outside the code shown below) I have added On and Off buttons to enable switching between the first and second buttons, these trigger onClickOn and onClickOff actions. I'm wondering how I can programmatically include some onClickOn / onClickOff actions within this set of code. Some guidelines to get me going would be very helpful.</p>

<pre><code>private class MyLocationListener implements LocationListener {
    public void onLocationChanged(Location loc) {
        if (loc != null) {

            /* 1st Chunk - Commented out to deactivate broadcasting current location.
            *
            //---send a SMS containing the current location---
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(senderTel, null,
                    senderTel+" is currently located at:\n\n" +
                    "http://maps.google.com/maps?t=m&amp;f=q&amp;q=loc:"
                    + loc.getLatitude() + ","
                    + loc.getLongitude() + "&amp;z=18", null, null);
            */ End 1st chunk

            // 2nd chunk - The active chunk of code currently being broadcast.
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(senderTel, null,
                    senderTel+" has suspended broadcasting his whereabouts for the time bieng but ", null, null);
            // End 2nd chunk

             /* 3rd chunk - The original sample message focused the map on 
              * Google HQ Tulsa and is inactive.

            // Used for capturing sample app screen shots---                
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(senderTel, null,
                    "http://maps.google.com/maps?z=18&amp;t=m&amp;f=q&amp;q=loc:37.422006,-122.084095", null, null);
             * End 3rd chunk
             */

            //---stop listening for location changes---
            lm.removeUpdates(locationListener);                
        }
    }
</code></pre>
