Why does the class get reloaded?
<p>I am creating an android app that will send a SMS to another SIM connected to an electrical circuit. When the receiving SIM gets the message with a particular text, the electrical circuit will be closed and a motor will start running. Here is the program</p>

<pre><code>public class SendSMSActivity extends Activity implements View.OnClickListener{
    ImageView image1;
    Button turnon;
    /** Called when the activity is first created. */
    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        turnon = (Button) findViewById(R.id.button1);
        image1 = (ImageView) findViewById(R.id.image1);
        turnon.setOnClickListener(this);
    }
    public void onClick(View v) 
            {                
                String phoneNo = "XXXXXXXXXX";
                String message = "Turn On";                 
                if (phoneNo.length()&gt;0 &amp;&amp; message.length()&gt;0)                
                    {
                    sendSMS(phoneNo, message);
                    image1.setImageResource(R.drawable.greenon);
                    }
                else{
                    Toast.makeText(getBaseContext(), 
                        "Phone Number and Message not configured correctly.", 
                        Toast.LENGTH_SHORT).show();
                    image1.setImageResource(R.drawable.redon);
            }
        }
    protected void sendSMS(String phoneNo, String message) {
        // TODO Auto-generated method stub
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, SendSMSActivity.class), 0);                
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNo, null, message, pi, null);

    }
}
</code></pre>

<p>The problem I have is that after the image comes up on the screen after the click, it doesn't stay on the screen. Instead the class gets reloaded and the image resets back to its original image. How can I get the image to stay on the screen without changing back to the original image.</p>
