3
我打開一個捕獲圖像和OnActivityResult的意圖,我調用一個AsyncTask開始對圖像進行一些處理。問題是我想先加載mainActivity,然後啓動AsyncTask以查看AsyncTask的百分比。我怎樣才能做到這一點?如何在ActivityResult上啓動一個AsyncTask並在MainActivity上顯示
@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);
}
}
}
開始MainActiviy並讓MainActivity啓動AsyncTask – Blackbelt
開始Mai OnActivityResult中的nActivity和MainActivity onCreate()中的啓動AsyncTask。 –
我如何在onActivityResult中啓動MainActivity? –