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 8159489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:55:57+00:00 2026-06-06T17:55:57+00:00

Does there is a way to run my AsyncTask after it finish ? My

  • 0

Does there is a way to run my AsyncTask after it finish ?

My app is to capture an image and put it on imagView then execute an AsyncTask on it.
I have another button to take another photo then put it put cannot execute an AysncTask.

I know form developer.Android that AsyncTask can not execute only except one time.

This is my code.

package com.ocr.id;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.ocr.id.ip.AndroidImage;
import com.ocr.id.ip.Binarization;
import com.ocr.id.ip.Crop;
import com.ocr.id.ip.Segement;

public class PreviewActivity extends Activity {

    private ImageView previewIV;
    private final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    private String path;
    private boolean crop = true;
    private boolean resample = true;
    Crop cropID;
    Binarization binary;
    Segement seg;
    ProgressDialog previewPD;

    OnClickListener processOnClickListener = new OnClickListener() {
        public void onClick(View v) {
            segementTask task = new segementTask();

            task.execute(path);
            }
    };

    private OnClickListener backOnClickListener = new OnClickListener() {
        public void onClick(View v) {
            startActivityForResult(
                    new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
                            MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(new File(path))),
                    CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    };

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
                previewIV.setImageBitmap(AndroidImage
                        .decodeSampledBitmapFromSDcard(path, 1000, 1000));
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preview);

        path = getIntent().getExtras().getString("path");

        previewIV = (ImageView) findViewById(R.id.previewPicID);

        Button process = (Button) findViewById(R.id.processID);
        process.setOnClickListener(processOnClickListener);

        Button back = (Button) findViewById(R.id.back);
        back.setOnClickListener(backOnClickListener);

        previewIV.setImageBitmap(AndroidImage.decodeSampledBitmapFromSDcard(
                path, 1000, 1000));
    }

    class segementTask extends AsyncTask<String, Integer, Void> {

        @Override
        protected void onPreExecute() {
            previewPD = ProgressDialog.show(PreviewActivity.this, "Id-OCR",
                    "Processing...");
            previewPD.setCancelable(false);
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(String... params) {
            try {
                seg = new Segement(PreviewActivity.this, params[0]);
                seg.segmentNumbers();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            previewPD.dismiss();
            previewPD = null;

            Toast.makeText(PreviewActivity.this, "Processing done",
                    Toast.LENGTH_LONG).show();
            super.onPostExecute(result);
        }
    }
}
  • 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-06T17:55:59+00:00Added an answer on June 6, 2026 at 5:55 pm

    You can’t run the same instance twice. But you can call new segmentTask().execute() as many times as you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to run some custom SQL statements after syncdb does it
Is there a way to run my own javascript after all JS files have
is there a way in Excel to have a formula that does something like
Does anyone know if there is a way to run a product collection through
Does anyone know if there's a way to run automatically in shell a list
Does anybody know if there is some way to run a piece of Javascript
Does anyone know is there a way to implement Windows Live ID authentication into
Is there a way for something to raise and exception that does not descend
Is there a way to get the status how long does it takes to
is there any way to dock two windows(like Winamp does with panels), but one

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.