Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:07:27+00:00 2026-06-13T12:07:27+00:00

I am new to stackoverflow! I have been working on an app in android,

  • 0

I am new to stackoverflow! I have been working on an app in android, but got stuck at a specific point.

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.

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.

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

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)

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

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.

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) {      
    ....
}

}

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.

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:07:28+00:00Added an answer on June 13, 2026 at 12:07 pm

    If I understand you correctly, you want to save the current canvas to a jpg as soon as a user hits a button. In such an interactive case, polling for a boolean to change is not the way you want to go about this. A user action is provoking an application action so you should tell the view to capture a picture when the user clicks the button.

    For instance, the view could have a method

      public void capturePicture(){
          // capture the canvas as a jpg
      }
    

    then in your onClick handler you’d simply invoke this method

    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(){
            final MyView theView = (MyView)findViewById(R.id.viewID);
            public void onClick(View v) {
                theView.capturePicture();          
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new here, working with Web Apps & SEO. StackOverflow has been a great
I have this code I been working on but I'm having a hard time
I'm kinda new in asking @Stackoverflow, however it's been the closest thing I have
I've been schooling myself through stackoverflow and elsewhere and have learned a lot, but
I'm new to programming and stackoverflow and have decided to start by learning objective
I'm new here to stackoverflow, so bear with me. I have a book that
I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
Brand new poster here on StackOverflow. I've been reading and learning here for some
The majority of my questions I've asked here so far on StackOverflow have been
am new to StackOverflow.. I am developing a website which requires extensive ORM...using asp.net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.