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

  • SEARCH
  • Home
  • 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 8923657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:11:23+00:00 2026-06-15T07:11:23+00:00

I am writing an app which should have the following use case: User clicks

  • 0

I am writing an app which should have the following use case: User clicks the ‘Start!’ button and the app starts clicking pictures (using CameraPreview class internally) every 1 minute and changes the button text to ‘Done!’.

When the user presses the same button (but with a new button text ‘Done!’), the app should stop.

I have been able to write the code which clicks the picture every one minute when the user clicks the ‘Start!’ button. But, once the image capturing starts, the button freezes.

How can I run my image-capture-every-1-minute logic in a way that the button doesn’t freeze? What are the best practices around that? Thanks!

Here is the code for OnClick():

    @Override
public void onClick(View v) {
    Button button = (Button)v;
    String buttonText = button.getText().toString();

    if(buttonText.equals(Constant.trainButtonText)) {
        Log.i(TAG, "Robot Training started...");

        while(true) {
            surfaceView.capture(new Camera.PictureCallback() {
                public void onPictureTaken(byte[] data, Camera camera) {
                    Log.v("Still", "Image data received from camera");

                    String[] params = new String[] {
                            Constant.Server, // Server URL
                            Long.toString(new Date().getTime()), // Image Timestamp
                            Constant.userId // Unique user ID for each customer
                    };
                    new UploadImageToWebServiceTask(data).execute(params);
                    camera.startPreview();
                }
            });
            try {
                // Capture every 1 minute until 'training done!' is not clicked
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
    else if(buttonText.equals(Constant.doneTrainingButtonText)) {
        Log.i(TAG, "Robot Training completed...");
        button.setText(Constant.trainButtonText);
        button.clearFocus();
    }
}

In the code the same button is used – only that we decide what to do based on the button text.

  • 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-15T07:11:24+00:00Added an answer on June 15, 2026 at 7:11 am

    Don’t block the UI thread, switch to a Runnable. Also you are taking a picture every second: 1000 is one second, 60000 is one minute.

    First create a new field variable:

    public class MainActivity extends Activity {
        Runnable takePictures = new Runnable() {
            @Override
            public void run() {
                // I'll trust that this code works
                surfaceView.capture(new Camera.PictureCallback() {
                    public void onPictureTaken(byte[] data, Camera camera) {
                        Log.v("Still", "Image data received from camera");
    
                        String[] params = new String[] {
                                Constant.skynetNNServer, // Server URL
                                Long.toString(new Date().getTime()), // Image Timestamp
                                Constant.userId // Unique user ID for each customer
                        };
                        new UploadImageToCloudTask(data).execute(params);
                        camera.startPreview();
                    }
                });
    
                // Call this runnable again in 60 seconds (60000 milliseconds) 
                surfaceView.postDelayed(this, 60000);
            }
        };
        // Rest of your code
    

    Then change your onClick method:

    @Override
    public void onClick(View v) {
        Button button = (Button)v;
        String buttonText = button.getText().toString();
    
        if(buttonText.equals(Constant.trainButtonText)) {
            Log.i(TAG, "Robot Training started...");
            surfaceView.post(takePictures);
        }
        else if(buttonText.equals(Constant.doneTrainingButtonText)) {
            Log.i(TAG, "Robot Training completed...");
            surfaceView.removeCallbacks(takePictures);
            button.setText(Constant.trainButtonText);
            button.clearFocus();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple android app which have a edittext and a button.
I'm writing delphi app which should have capability of loading plugins. I'm using JvPluginManager
I am writing a really simple app which should be quick to use. I
I'm writing an iPhone app with a UIWebView which should display various html files
I am writing an app which needs to have both the traditional form of
I'm writing a Rails app which has the following jasmine spec: describe buttons, ->
I'm writing a diagnostic app which needs to log what the user has set
I'm writing an app which will rely heavily on the use of a database.
I am writing a web app which will allow the user to specify a
I'm writing small VB.Net app which should build reports based on data gathered from

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.