我打开了一个捕获图像的意图,并且 OnActivityResult 我调用了一个 AsyncTask 来开始对图像进行一些处理。问题是我想先加载 mainActivity 然后启动 AsyncTask 以查看 AsyncTask 的百分比。我怎样才能做到这一点?
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
try {
rotationIfNeeded();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v(TAG, "C");
retrievePreferences();
OcrAsyncTask aTask = new OcrAsyncTask(dialog, languageCode, languagePath, bitmap);
aTask.execute(languagePath);
while (aTask.doInBackground(languagePath)){
//Do Nothing
}
recognizedText = aTask.getRecognizedText();
Log.v(TAG, "The Recognized Text is = " + aTask.getRecognizedText());
if ( recognizedText.length() != 0 ) {
ocrResult.setText(ocrResult.getText().toString().length() == 0 ? recognizedText : ocrResult.getText() + " " + recognizedText);
ocrResult.setSelection(ocrResult.getText().toString().length());
}
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
} else {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
}
}
}