How to continuously check the state of a boolean in a custom view that was sent from an activity? In Android
<p>I am new to stackoverflow! I have been working on an app in android, but got stuck at a specific point.</p>

<p>I have an activity (activity 1) which has four buttons and a canvas drawn to it. The canvas is created in a custom view (view 1) which is then drawn to the acitivty through an xml file. I want to save the canvas as a jpg file to my sd card. The action of saving has to happen at a button press.</p>

<p>How I intended it to work was as follows: By clicking on the button a boolean is set to true. This boolean has to be sent from activity 1 to the view 1 in which the canvas is drawn. This view 1 would then monitor if the boolean is set to true or false. If the boolean is set to true a snippet of code would run that would save the canvas to a jpg.</p>

<p>My problem is at the monitoring of the boolean. How can I continuoisly monitor the state of the boolean in a custom view(view 1)?</p>

<p>Activity 1: So here I have my main activity in which I have a button that sets the boolean to true when clicked. (I stripped down the code to the essential part for the forum)</p>

<pre><code>public class ShowImage extends Activity implements ColorPickerDialog.OnColorChangedListener {

 public boolean saveCanvas = false;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.image);

 Button saveButton = (Button)findViewById(R.id.savePic);
    saveButton.setOnClickListener(saveListener);
}

private OnClickListener saveListener = new OnClickListener(){
    public void onClick(View v) {
        saveCanvas = true;          
};
</code></pre>

<p>View 1: This is the custom view I created in which the canvas is drawn. In this code I want to continuously monitor the state of the boolean that I just created in Acitivty 1.</p>

<pre><code>public class MyView extends View {

    boolean saveCanvas = false;

Context context;

public MyView(Context c, AttributeSet as) {
    super(c, as);
    ....    
}

//CONTINUOUSLY MONITOR THE STATE OF THE BOOLEAN
//IF TRUE SAVE PICTURE, ELSE CONTINUE CODE

 @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {            
    super.onSizeChanged(w, h, oldw, oldh);        
    ....
}

@Override
protected void onDraw(Canvas canvas) {      
    ....
}

}
</code></pre>

<p>I hope my question is somehow clear and hopefully I provided enough of my code to have someone help me out. Please let me know if additional information is needed. </p>

<p>Cheers! </p>
